public static void InitLogConfig() { if (IsInitialized) { Log.Warning("An atempt was made to Initialize the log configuration after it was already initialized!"); return; } var logLevel = LogEventLevel.Debug; if (!ApplicationBuildConfig.DebugMode) { logLevel = LogEventLevel.Warning; } Log.Logger = new LoggerConfiguration() //.WriteTo.LiterateConsole(LogEventLevel.Debug, standardErrorFromLevel: LogEventLevel.Error, formatProvider: CultureInfo.InvariantCulture) .WriteTo.RollingFile(ApplicationBuildConfig.ApplicationLogFilePath(true), fileSizeLimitBytes: 1048576, retainedFileCountLimit: 31, restrictedToMinimumLevel: logLevel, buffered: false, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.ff} [{Level}] {Message}{NewLine}{Exception}{Data}") .Enrich.FromLogContext() .MinimumLevel.Is(logLevel) .CreateLogger(); Log.Debug("LogConfiguration completed init."); IsInitialized = true; }
// If debug use executing assembly path otherwise use appdata public static void ConfigureSerilog() { var logLevel = !ApplicationBuildConfig.DebugMode ? LogEventLevel.Warning : LogEventLevel.Verbose; Log.Logger = new LoggerConfiguration() .WriteTo.LiterateConsole(LogEventLevel.Debug, standardErrorFromLevel: LogEventLevel.Error, formatProvider: CultureInfo.InvariantCulture) .WriteTo.RollingFile(ApplicationBuildConfig.ApplicationLogFilePath(true), fileSizeLimitBytes: 1048576, retainedFileCountLimit: 31, restrictedToMinimumLevel: logLevel, buffered: false, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.ff} [{Level}] {Message}{NewLine}{Exception}{Data}") .Enrich.FromLogContext() .Enrich.WithProperty("Version", Assembly.GetCallingAssembly().GetName().Version.ToString(4)) .MinimumLevel.Is(logLevel) .CreateLogger(); }
protected override void Load(ContainerBuilder builder) { var logLevel = LogEventLevel.Debug; if (!ApplicationBuildConfig.DebugMode) { logLevel = LogEventLevel.Warning; } Log.Logger = new LoggerConfiguration() .WriteTo.RollingFile(ApplicationBuildConfig.ApplicationLogFilePath(true), fileSizeLimitBytes: 1048576, retainedFileCountLimit: 31, restrictedToMinimumLevel: logLevel, buffered: false, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.ff} [{Level}] {Message}{NewLine}{Exception}{Data}") .Enrich.FromLogContext() .MinimumLevel.Is(logLevel) .CreateLogger(); builder.RegisterLogger(); }
protected override void Load(ContainerBuilder builder) { var logLevel = LogEventLevel.Information; if (!ApplicationBuildConfig.DebugMode) { logLevel = LogEventLevel.Warning; } Log.Logger = new LoggerConfiguration() .WriteTo.Console(LogEventLevel.Debug, standardErrorFromLevel: LogEventLevel.Error, formatProvider: CultureInfo.InvariantCulture) .WriteTo.File(ApplicationBuildConfig.ApplicationLogFilePath(), fileSizeLimitBytes: 1048576, retainedFileCountLimit: 20, restrictedToMinimumLevel: logLevel, buffered: false, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.ff} [{Level}] {Message}{NewLine}{Exception}{Data}") .Enrich.FromLogContext() .MinimumLevel.Is(logLevel) .CreateLogger(); builder.RegisterLogger(); }