/// <summary>
        /// New provider with options
        /// </summary>
        /// <param name="options"></param>
        public Log4NetLoggerProvider(Log4NetProviderOptions options)
        {
            _loggerRepository = LogManager.CreateRepository(options.RepositoryAssembly ?? Assembly.GetEntryAssembly(),
                                                            typeof(log4net.Repository.Hierarchy.Hierarchy));

            Options = MergeOptions(options ?? Log4NetProviderOptions.Default);
        }
Exemple #2
0
        internal Log4NetLogger(string loggerRepository, string name, Log4NetProviderOptions options, IExternalScopeProvider scopeProvider)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            _options = options;
            _log     = LogManager.GetLogger(loggerRepository, name);

            ScopeProvider = scopeProvider;
        }
        private Log4NetProviderOptions MergeOptions(Log4NetProviderOptions options)
        {
            if (options == null)
            {
                return(Log4NetProviderOptions.Default);
            }

            if (options.ExceptionFormatter == null)
            {
                options.ExceptionFormatter = Log4NetProviderOptions.Default.ExceptionFormatter;
            }

            if (options.PropertiesAccessor == null)
            {
                options.PropertiesAccessor = Log4NetProviderOptions.Default.PropertiesAccessor;
            }

            return(options);
        }
 static Log4NetProviderOptions()
 {
     Default = new Log4NetProviderOptions
     {
         RepositoryAssembly        = null,
         IncludeScopes             = false,
         ConfigurationFileFullName = "log4net.config",
         JsonConfiguration         = null,
         PropertiesAccessor        = state => new Log4NetProperties
         {
             Code    = null,
             Source  = null,
             Message = null
         },
         UserNameAccessor   = state => null,
         Configure          = null,
         ExceptionFormatter = (state, exception) => $"{state.ToString()} - {exception.Message}",
     };
 }
Exemple #5
0
 public Log4NetLogger(string loggerRepository, string name, Log4NetProviderOptions options)
     : this(loggerRepository, name, options, options.IncludeScopes ? new LoggerExternalScopeProvider() : null)
 {
 }