public Logger(LoggerCfg config, LoggingLevelSwitch levelSwitch) { Config = config; LevelSwitch = levelSwitch; RegisterExceptionLoggers(); LogTo.Debug("Logger initialized"); }
public static ILogger CreateSerilog( string appName, LoggerCfg loggerCfg = null, LoggingLevelSwitch levelSwitch = null, LoggerConfigPredicate configPredicate = null) { var loggerConfig = new LoggerConfiguration() .Enrich.WithExceptionDetails() .Enrich.WithDemystifiedStackTraces() .WriteTo.Debug(outputTemplate: OutputFormat) .WriteTo.Async( a => a.RollingFile( GetLogFilePath(appName).FullPath, fileSizeLimitBytes: Math.Max(loggerCfg?.LogMaxSize ?? 5242880, 10485760), retainedFileCountLimit: 7, shared: true, outputTemplate: OutputFormat )); //.WriteTo.File( // GetLogFilePath(appName).FullPath, // outputTemplate: OutputFormat); //.WriteTo.RollingFile( // GetLogFilePath(appName).FullPath, // fileSizeLimitBytes: 5242880, // retainedFileCountLimit: 7, // shared: false, // outputTemplate: OutputFormat //); if (levelSwitch != null) { loggerConfig = loggerConfig.MinimumLevel.ControlledBy(levelSwitch); } if (configPredicate != null) { loggerConfig = configPredicate(loggerConfig); } return(loggerConfig.CreateLogger()); }
public void ReloadConfig(ConfigurationServiceBase sharedCfg) { var newConfig = LoggerFactory.LoadConfig(sharedCfg); SetMinimumLevel(newConfig.LogLevel); if (newConfig.LogFirstChanceExceptions != Config.LogFirstChanceExceptions) { if (newConfig.LogFirstChanceExceptions) { RegisterFirstChanceExceptionLogger(); } else { UnregisterFirstChanceExceptionLogger(); } } Config = newConfig; }
public void ReloadConfig() { var newConfig = LoadConfig(); SetMinimumLevel(newConfig.LogLevel); if (newConfig.LogFirstChanceExceptions != _config.LogFirstChanceExceptions) { if (newConfig.LogFirstChanceExceptions) { RegisterFirstChanceExceptionLogger(); } else { UnregisterFirstChanceExceptionLogger(); } } _config = newConfig; }
public void Initialize( string appName, LoggerConfigPredicate configPredicate = null) { _config = LoadConfig(); LevelSwitch = new LoggingLevelSwitch(_config.LogLevel); var config = new LoggerConfiguration() .MinimumLevel.ControlledBy(LevelSwitch) .Enrich.WithExceptionDetails() .Enrich.WithDemystifiedStackTraces() .WriteTo.Debug(outputTemplate: OutputFormat) //.WriteTo.RollingFile( // GetLogFilePath(appName).FullPath, // fileSizeLimitBytes: 5242880, // retainedFileCountLimit: 7, // shared: false, // outputTemplate: OutputFormat //); .WriteTo.Async( a => a.RollingFile( GetLogFilePath(appName).FullPath, fileSizeLimitBytes: 5242880, // Math.Max(ConfigMgr.AppConfig.LogMaxSize, 5242880), retainedFileCountLimit: 7, shared: false, outputTemplate: OutputFormat )); if (configPredicate != null) { config = configPredicate(config); } Log.Logger = config.CreateLogger(); LogTo.Debug("Logger initialized"); RegisterExceptionLoggers(); }
internal async Task ReloadConfigFromFile(ConfigurationServiceBase cfgService) { Config = await cfgService.Load <LoggerCfg>(); ReloadConfig(); }