Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 1.7 KB

README.md

File metadata and controls

43 lines (35 loc) · 1.7 KB

Serilog Logging

NuGet Downloads License

How to use

You should be registering serilog in your Program.cs.

Inside ConfigureServices method Invoke

services.RegisterSerilogLogger(
            Configuration, // See [IConfiguration](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfiguration?view=dotnet-plat-ext-7.0)
            typeof(Program).Assembly.GetName().Version.ToString(),
            "RequestPath like '/Account/Login%'",
            "RequestPath like '/Account/Register%'",
            "@l in ['Information'] and RequestPath like '%/_system/%'");

Inside Configure method add

app.UseCorrelationIdMiddleware("MyCorrelationId"); // Defaults to CorrelationId if no value passed
app.UseSerilogRequestLogging(options => options.EnrichDiagnosticContext = HttpContextEnricher.HttpRequestEnricher);

Example project

Example project can be found in example folder You can run it by running following docker command inside the example folder:

docker-compose up --build

This will run following services

Service Url
API http://localhost:5000
Seq http://localhost:5341

For more info check: https://biplov.dev/enriching-serilog-log-entries