Need to implement the serilog intergration through ioptions pattern.

Mani kanta 1 Reputation point
2022-07-08T08:56:35.867+00:00

Need to implement the serilog integration through ioption pattern i have implemented serilog integration like below. Need to implement using Ioption pattern. Please help me on this.

program.cs
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);

Appsettings.json

"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../logs/webapi-.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {Level:u3}] {Username} {Message:lj}{NewLine}{Exception}"
}
}
]
}

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,188 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,277 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,766 Reputation points
    2022-07-09T19:36:21.233+00:00

    You question is not clear. The Options pattern stores configuration as as a dynamic object that is injected to modules that use the configuration.

    Are you saying you want to rewrite the serilog provider to use the pattern to support dynamic config? Google dynamic serilog for examples.


  2. Rijwan Ansari 746 Reputation points MVP
    2022-07-11T14:15:09.34+00:00

    Hi,

    This article shows a simple way to implement serilog. Check if this can help you.

    https://rijsat.com/2021/02/18/serilog-implementation-in-asp-net-core-5-0-with-database/