Make Simple .NET logging config and tracing in microservices architecture
Install from Nuget
$ dotnet add package MakeSimple.Logging
Config Program.cs
public static void Main(string[] args)
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
....
}
Config Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddMakeSimpleLoging(new LoggingOption()
{
IsOffLogSystem = bool.Parse(Environment.GetEnvironmentVariable("ISOFF_LOG_SYSTEM")),
MinimumLevel = (LoggerLevel)int.Parse(Environment.GetEnvironmentVariable("LOG_LEVEL"))
});
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
...
app.AddMakeSimpleLoging();
...
}
LogContext.PushProperty("CustomerInfo", "Example");
Property | Type | Description |
---|---|---|
Timestamp | Datetime | ISO8601 |
Level | String | |
Exception | String | |
Message | String | |
SpanId | String Id | Trace context |
TraceId | String Id | Trace context |
ParentId | String Id | Trace context |
Method | String | |
QueryString | String | |
Payload | String | |
RequestedOn | Datetime | |
Response | String | |
ResponseCode | String | |
RespondedOn | Datetime | |
... | ... |
Level | Value | Description |
---|---|---|
Information | 0 | |
Verbose | 1 | |
Debug | 2 | |
Error | 3 | |
Fatal | 4 | |
Warning | 5 |