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}"
}
}
]
}

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    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 766 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/


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.