当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationItemFactory.RegisterExtendedItems方法代码示例

本文整理汇总了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;
        }
开发者ID:Xharze,项目名称:NLog,代码行数:32,代码来源:ConfigurationItemFactory.cs

示例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;
        }
开发者ID:JvanderStad,项目名称:NLog,代码行数:11,代码来源:ConfigurationItemFactory.cs

示例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;
        }
开发者ID:ie-zero,项目名称:NLog,代码行数:75,代码来源:ConfigurationItemFactory.cs


注:本文中的NLog.Config.ConfigurationItemFactory.RegisterExtendedItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。