本文整理汇总了C#中NLog.Config.ConfigurationItemFactory.RegisterExtendedItems方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationItemFactory.RegisterExtendedItems方法的具体用法?C# ConfigurationItemFactory.RegisterExtendedItems怎么用?C# ConfigurationItemFactory.RegisterExtendedItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLog.Config.ConfigurationItemFactory
的用法示例。
在下文中一共展示了ConfigurationItemFactory.RegisterExtendedItems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildDefaultFactory
/// <summary>
/// Builds the default configuration item factory.
/// </summary>
/// <returns>Default factory.</returns>
private static ConfigurationItemFactory BuildDefaultFactory()
{
var nlogAssembly = typeof(ILogger).Assembly;
var factory = new ConfigurationItemFactory(nlogAssembly);
factory.RegisterExtendedItems();
#if !SILVERLIGHT
var assemblyLocation = Path.GetDirectoryName(nlogAssembly.Location);
if (assemblyLocation == null)
{
return factory;
}
var extensionDlls = Directory.GetFiles(assemblyLocation, "NLog*.dll")
.Select(Path.GetFileName)
.Where(x => !x.Equals("NLog.dll", StringComparison.OrdinalIgnoreCase))
.Where(x => !x.Equals("NLog.UnitTests.dll", StringComparison.OrdinalIgnoreCase))
.Where(x => !x.Equals("NLog.Extended.dll", StringComparison.OrdinalIgnoreCase))
.Select(x => Path.Combine(assemblyLocation, x));
foreach (var extensionDll in extensionDlls)
{
InternalLogger.Info("Auto loading assembly file: {0}", extensionDll);
var extensionAssembly = Assembly.LoadFrom(extensionDll);
factory.RegisterItemsFromAssembly(extensionAssembly);
}
#endif
return factory;
}
示例2: BuildDefaultFactory
/// <summary>
/// Builds the default configuration item factory.
/// </summary>
/// <returns>Default factory.</returns>
private static ConfigurationItemFactory BuildDefaultFactory()
{
var factory = new ConfigurationItemFactory(typeof(Logger).Assembly);
factory.RegisterExtendedItems();
return factory;
}
示例3: BuildDefaultFactory
/// <summary>
/// Builds the default configuration item factory.
/// </summary>
/// <returns>Default factory.</returns>
private static ConfigurationItemFactory BuildDefaultFactory()
{
var nlogAssembly = typeof(ILogger).Assembly;
var factory = new ConfigurationItemFactory(nlogAssembly);
factory.RegisterExtendedItems();
#if !SILVERLIGHT
var assemblyLocation = Path.GetDirectoryName(new Uri(nlogAssembly.CodeBase).LocalPath);
if (assemblyLocation == null)
{
InternalLogger.Warn("No auto loading because Nlog.dll location is unknown");
return factory;
}
if (!Directory.Exists(assemblyLocation))
{
InternalLogger.Warn("No auto loading because '{0}' doesn't exists", assemblyLocation);
return factory;
}
try
{
var extensionDlls = Directory.GetFiles(assemblyLocation, "NLog*.dll")
.Select(Path.GetFileName)
.Where(x => !x.Equals("NLog.dll", StringComparison.OrdinalIgnoreCase))
.Where(x => !x.Equals("NLog.UnitTests.dll", StringComparison.OrdinalIgnoreCase))
.Where(x => !x.Equals("NLog.Extended.dll", StringComparison.OrdinalIgnoreCase))
.Select(x => Path.Combine(assemblyLocation, x));
InternalLogger.Debug("Start auto loading, location: {0}", assemblyLocation);
foreach (var extensionDll in extensionDlls)
{
InternalLogger.Info("Auto loading assembly file: {0}", extensionDll);
var success = false;
try
{
var extensionAssembly = Assembly.LoadFrom(extensionDll);
InternalLogger.LogAssemblyVersion(extensionAssembly);
factory.RegisterItemsFromAssembly(extensionAssembly);
success = true;
}
catch (Exception ex)
{
if (ex.MustBeRethrownImmediately())
{
throw;
}
InternalLogger.Warn(ex, "Auto loading assembly file: {0} failed! Skipping this file.", extensionDll);
//TODO NLog 5, check MustBeRethrown()
}
if (success)
{
InternalLogger.Info("Auto loading assembly file: {0} succeeded!", extensionDll);
}
}
}
catch (UnauthorizedAccessException ex)
{
InternalLogger.Warn(ex, "Seems that we do not have permission");
if (ex.MustBeRethrown())
{
throw;
}
}
InternalLogger.Debug("Auto loading done");
#endif
return factory;
}