I am new to programming, I am trying to implement a logging solution for .net core project.
I want to collect Default and Microsoft category logs.
APPSETTING.JSON
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"System": "Warning",
"Microsoft": "Information"
},
"File": {
"location": "logs/timeapi.log"
}
},
"EnableSwagger": true
}
PROGRAM.CS
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilogRequestLogging();
STARTUP.CS
app.UseSerilogRequestLogging(options =>
options.RequestProjection =
r => new { r.IsHttps, QueryString = r.QueryString.Value });
app.UseMvc();
https://github.com/mthamil/AspNetCore.Serilog.RequestLoggingMiddleware
The error I am getting is :
Unable to resolve service for type 'Serilog.ILogger' while attempting to activate 'AspNetCore.Serilog.RequestLoggingMiddleware.SerilogRequestMiddleware'.
Introduction. Serilog is a structural logging library for Microsoft . Net and has become the preferred logging library for . Net applications.
The middleware you're using appears to need Serilog's ILogger
added in the app's Startup.ConfigureServices()
method; e.g.:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ILogger>(Log.Logger);
}
(This example assumes you're configuring Serilog's Log.Logger
static property.)
There's a more complete example of setting up request logging with Serilog in the readme for the Serilog.AspNetCore package, though its implementation of UseSerilogRequestLogging()
is quite different.
if you are using .net core 3.1 + only use it in program.cs like this and remove every thing about Serilog from startup.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.WriteTo.Console())
......;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With