{ "Serilog": { "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Information", "System": "Warning", "Microsoft.AspNetCore": "Warning", "Microsoft.EntityFrameworkCore": "Error", "Orleans.Runtime.SiloLogStatistics": "Warning", "Orleans.Runtime.GrainDirectory.LocalGrainDirectory": "Warning", "Orleans.Runtime.Management.ManagementGrain": "Warning", "Orleans.Runtime.ReminderService.LocalReminderService": "Warning", "Orleans.Runtime.DeploymentLoadPublisher": "Warning", "Orleans.Runtime.SiloControl": "Warning", "Orleans.Runtime.CounterStatistic": "Warning", "Orleans.Runtime.MembershipService.MembershipTableManager": "Warning" } }, "WriteTo": [ { "Name": "Console", "Args": { "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console", "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Level:u3} {Message} <{SourceContext}> {NewLine}{Exception}]" //"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact" } } //{ // "Name": "File", // "Args": { // "path": "logs/log.txt", // "rollingInterval": "Day", // "retainedFileCountLimit": 60, // "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Level:u3} {Message} <{SourceContext}> {NewLine}{Exception}]", // "fileSizeLimitBytes": 3145728 //3M default 1G // "rollOnFileSizeLimit": true // } //}, //{ // "Name": "EventCollector", // "Args": { // "splunkCollectorBatchIntervalInSeconds": "100", // "splunkCollectorBatchSizeLimit": "2", // "auditLoggingSourceType": "DistributedCluster", // "splunkHost": "http://localhost", // "eventCollectorToken": "some-GUID-here" // } //} ], "Properties": { "Application": "DstributedService" } } }
private static readonly string Env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
#region Serilog var loggingConfig = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithMachineName() .Enrich.WithThreadId() .Enrich.WithProperty("Environment", Env) .ReadFrom.Configuration(new ConfigurationBuilder() .AddJsonFile("Serilog.json") .Build()); if (Env == "Development") { var levelSwitch = new LoggingLevelSwitch(); levelSwitch.MinimumLevel = LogEventLevel.Debug; loggingConfig.MinimumLevel.ControlledBy(levelSwitch); } Log.Logger = loggingConfig.CreateLogger(); #endregion