JsonConsole logger provider implementation for Microsoft.Extensions.Logging.
Outputs json formatted logs to stdout/console.
Ideal for high performance centralised structured logging in environments such as Kubernetes with EFK stack (Elasticsearch/Fluent-Bit/Kibana).
PM> Install-Package Nvosk.Extensions.Logging.JsonConsole
The "JsonMessageTemplate" section is optional.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"Console": {
"Format": "Json",
"TimestampFormat": "yyyy-MM-ddTHH:mm:ss",
"LogToStandardErrorThreshold": "Warning",
"LogLevel": {
"Default": "Information"
},
"JsonMessageTemplate": {
"TimeStamp": "time",
"LogLevel": "level",
"Source": "source",
"EventId": "event_id",
"Message": "message",
"Exception": "exception"
}
}
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureLogging((hostContext, configLogging) =>
{
// clear all previously registered providers
configLogging.ClearProviders();
configLogging.AddConfiguration(hostContext.Configuration.GetSection("Logging"));
configLogging.AddJsonConsole();
})
.UseStartup<Startup>();
});
{"time":"2019-12-31T23:59:54","level":"trce","source":"ConsoleApp.Program","event_id":0,"message":"LogTrace..."}
{"time":"2019-12-31T23:59:55","level":"dbug","source":"ConsoleApp.Program","event_id":0,"message":"LogDebug..."}
{"time":"2019-12-31T23:59:56","level":"info","source":"ConsoleApp.Program","event_id":0,"message":"LogInformation..."}
{"time":"2019-12-31T23:59:57","level":"warn","source":"ConsoleApp.Program","event_id":0,"message":"LogWarning..."}
{"time":"2019-12-31T23:59:58","level":"fail","source":"ConsoleApp.Program","event_id":0,"message":"LogError..."}
{"time":"2019-12-31T23:59:59","level":"crit","source":"ConsoleApp.Program","event_id":0,"message":"LogCritical..."}
- Updated Microsoft.Extensions.* packages to v3.1.17
- Updated System.Text.Json to v5.0.2
- Updated Microsoft.Extensions.* packages to v3.1.13
- Updated Microsoft.Extensions.* packages to v3.1.12
- Updated Microsoft.Extensions.* packages to v3.1.9
- Updated Microsoft.Extensions.* packages to v3.1.8
- Updated Microsoft.Extensions.* packages to v3.1.7
- Updated Microsoft.Extensions.* packages to v3.1.6
- Updated Microsoft.Extensions.* packages to v3.1.5
- Downgraded TargetFramework from netstandard2.1 to netstandard2.0 to reflect original Microsoft.Extensions.Logging.Console
- Updated Microsoft.Extensions.* packages to v3.1.4
- Updated System.Text.Json to v4.7.2
- Updated Microsoft.Extensions.* packages to v3.1.3
- Updated Microsoft.Extensions.* packages to v3.1.2
- Updated System.Text.Json to v4.7.1
- Updated Microsoft.Extensions.* packages to v3.1.1
- Updated Microsoft.Extensions.* packages to v3.1.0
- Updated System.Text.Json to v4.7.0
- Based on Microsoft.Extensions.Logging.Console v3.0.0.
- All original functionality from Microsoft.Extensions.Logging.Console is included.
- Via the new "Format" property one can switch between Default, Json or Systemd formats.
- Replaced Newtonsoft.Json with Microsoft's new high performance System.Text.Json.Utf8JsonWriter.
- Breaking changes: please review your appsettings.json files as there are some renames and new additions.
- Based on Microsoft.Extensions.Logging.Console v2.2.0.
- Initial JsonConsole.