private static void AttachToLog4Net(Serilog.ILogger logger, string loggerName, string level) { var serilogAppender = new SerilogAppender(logger); serilogAppender.ActivateOptions(); var log = log4net.LogManager.GetLogger(Assembly.GetEntryAssembly(), loggerName); var wrapper = (log4net.Repository.Hierarchy.Logger)log.Logger; wrapper.Level = wrapper.Hierarchy.LevelMap[level]; wrapper.AddAppender(serilogAppender); wrapper.Repository.Configured = true; }
/// <summary> /// Configures log4net to log to Serilog. /// </summary> /// <param name="logger">The serilog logger (if left null Log.Logger will be used).</param> public static void Configure(ILogger logger = null) { var serilogAppender = new SerilogAppender(logger); serilogAppender.ActivateOptions(); var loggerRepository = (Hierarchy)LogManager.GetRepository(Assembly.GetCallingAssembly()); if (loggerRepository.Root.GetAppender(serilogAppender.Name) == null) { loggerRepository.Root.AddAppender(serilogAppender); } loggerRepository.Configured = true; }
private static void ConfigureAwsLogging() { var log4NetLevel = Log.IsEnabled(LogEventLevel.Verbose) ? "ALL" : Log.IsEnabled(LogEventLevel.Debug) ? "DEBUG" : Log.IsEnabled(LogEventLevel.Information) ? "INFO" : Log.IsEnabled(LogEventLevel.Warning) ? "WARN" : Log.IsEnabled(LogEventLevel.Error) ? "ERROR" : Log.IsEnabled(LogEventLevel.Fatal) ? "FATAL" : "OFF"; var serilogAppender = new SerilogAppender(Log.Logger); serilogAppender.ActivateOptions(); var log = log4net.LogManager.GetLogger(Assembly.GetEntryAssembly(), "Amazon"); var wrapper = (log4net.Repository.Hierarchy.Logger)log.Logger; wrapper.Level = wrapper.Hierarchy.LevelMap[log4NetLevel]; wrapper.AddAppender(serilogAppender); wrapper.Repository.Configured = true; AWSConfigs.LoggingConfig.LogTo = LoggingOptions.Log4Net; AWSConfigs.LoggingConfig.LogMetricsFormat = LogMetricsFormatOption.Standard; }