本文整理汇总了C#中ILoggerFactory.MakeNewLoggerInstance方法的典型用法代码示例。如果您正苦于以下问题:C# ILoggerFactory.MakeNewLoggerInstance方法的具体用法?C# ILoggerFactory.MakeNewLoggerInstance怎么用?C# ILoggerFactory.MakeNewLoggerInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILoggerFactory
的用法示例。
在下文中一共展示了ILoggerFactory.MakeNewLoggerInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLogger
/// <summary>
/// Return a new logger instance named as the first parameter using
/// <paramref name="factory"/>.
/// </summary>
/// <remarks>
/// If a logger of that name already exists, then it will be
/// returned. Otherwise, a new logger will be instantiated by the
/// <paramref name="factory"/> parameter and linked with its existing
/// ancestors as well as children.
/// </remarks>
/// <param name="name">The name of the logger to retrieve</param>
/// <param name="factory">The factory that will make the new logger instance</param>
/// <returns>The logger object with the name specified</returns>
public Logger GetLogger(string name, ILoggerFactory factory)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (factory == null)
{
throw new ArgumentNullException("factory");
}
LoggerKey key = new LoggerKey(name);
// Synchronize to prevent write conflicts. Read conflicts (in
// GetEffectiveLevel() method) are possible only if variable
// assignments are non-atomic.
Logger logger;
lock(m_ht)
{
Object node = m_ht[key];
if (node == null)
{
logger = factory.MakeNewLoggerInstance(name);
logger.Hierarchy = this;
m_ht[key] = logger;
UpdateParents(logger);
FireLoggerCreationEvent(logger);
return logger;
}
else if (node is Logger)
{
return (Logger)node;
}
else if (node is ProvisionNode)
{
logger = factory.MakeNewLoggerInstance(name);
logger.Hierarchy = this;
m_ht[key] = logger;
UpdateChildren((ProvisionNode)node, logger);
UpdateParents(logger);
FireLoggerCreationEvent(logger);
return logger;
}
else
{
// It should be impossible to arrive here
return null; // but let's keep the compiler happy.
}
}
}