示例#1
0
        private Log4NetLogger CreateLoggerImplementation(string name)
        {
            var options = new Log4NetProviderOptions
            {
                Name = name,
                LoggerRepositoryName = _loggerRepository.Name
            };

            return(new Log4NetLogger(options));
        }
示例#2
0
        /// <summary>Ctor
        /// </summary>
        public Log4NetProvider(Log4NetProviderOptions options)
        {
            _options          = options;
            _loggerRepository = LogManager.CreateRepository(options.LoggerRepositoryName);
            var file = new FileInfo(options.Log4NetConfigFile);

            if (!file.Exists)
            {
                file = new FileInfo(Path.Combine(AppContext.BaseDirectory, options.Log4NetConfigFile));
            }
            if (file.Exists)
            {
                XmlConfigurator.ConfigureAndWatch(_loggerRepository, file);
            }
            else
            {
                BasicConfigurator.Configure(_loggerRepository, new ConsoleAppender {
                    Layout = new PatternLayout()
                });
            }
        }
示例#3
0
 /// <summary>Ctor
 /// </summary>
 public Log4NetLogger(Log4NetProviderOptions options)
 {
     _log = LogManager.GetLogger(options.LoggerRepositoryName, options.Name);
 }
示例#4
0
 /// <summary>添加Log4Net
 /// </summary>
 /// <param name="builder">ILoggingBuilder</param>
 /// <param name="options">配置选项</param>
 /// <returns></returns>
 public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder, Log4NetProviderOptions options)
 {
     builder.Services.AddSingleton <ILoggerProvider>(new Log4NetProvider(options));
     return(builder);
 }
示例#5
0
        /// <summary>添加Log4Net
        /// </summary>
        /// <param name="builder">ILoggingBuilder</param>
        /// <param name="configFile">配置文件</param>
        /// <returns></returns>
        public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder, string configFile)
        {
            var options = new Log4NetProviderOptions(configFile);

            return(builder.AddLog4Net(options));
        }
示例#6
0
        /// <summary>添加Log4Net
        /// </summary>
        /// <param name="builder">ILoggingBuilder</param>
        /// <returns></returns>
        public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder)
        {
            var options = new Log4NetProviderOptions();

            return(builder.AddLog4Net(options));
        }
示例#7
0
 /// <summary>添加Log4Net
 /// </summary>
 /// <param name="factory">工厂</param>
 /// <param name="options">配置选项</param>
 /// <returns></returns>
 public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, Log4NetProviderOptions options)
 {
     factory.AddProvider(new Log4NetProvider(options));
     return(factory);
 }