Substantive.Extensions.Logging 9.0.0-build20250629r1
AspNetCore.SerilogLogger is a library for quick setup log provider with Serilog library to diagnostic logging to files, the console, and elsewhere.
Installation
1. Add configuration to the appsettings.json
Add below configuration. Skip this step will use default configuration.
- Using: for using other library to work with serilog.
- Enrich: It simple components that add, remove or modify the properties attached to a log event. This can be used for the purpose of attaching a thread id to each event.
- MinimumLevel: The configuration object provides for one of the log event levels to be specified as the minimum. if no
MinimumLevelis specified, thenInformationlevel events and higher will be processed. - WriteTo: Configuration record logging to file, the console, and many other outputs.
- For configuration WriteToFile
- For configuration WriteToConsole
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Enrichers.Environment", "Serilog.Enrichers.ClientInfo", "Serilog.Enrichers.AspNetCore.HttpContext" ],
"Enrich": [ "FromLogContext", "WithMachineName", "WithClientIp", "WithClientAgent" ],
"MinimumLevel": {
"Default": "Information"
},
"Properties": {
"ApplicationName": "Playground API"
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {CorrelationId} {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "_Logs/.txt",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {CorrelationId} {Message:lj}{NewLine}{Exception}",
"shared": true,
"rollingInterval": "Day",
"retainedFileCountLimit": 90
}
}
]
}
}
2. Add dependencies to the program.cs
Call AddSerilogLogging In Program.cs file.
Have 2 options to config.
- With configuration in
appsetting.jsonfile by sending value theIConfigurationSection
builder.Services.AddSerilogLogging(builder.Configuration, "Serilog");
- Use serilog default value.
builder.Services.AddSerilogLogging();
Usage
Register ILogger in class or controller.
private readonly ILogger<CustomerController> _logger;
public WeatherForecastController(ILogger<CustomerController> logger)
{
_logger = logger;
}
public IEnumerable<Customer> Get()
{
// Logging the data.
_logger.LogInformation("Serilog is Working");
}
References
- Configuration Basics · serilog/serilog Wiki · GitHub
- serilog/serilog-sinks-file: Write Serilog events to files in text and JSON formats, optionally rolling on time or size
- serilog/serilog-sinks-console: Write log events to System.Console as text or JSON, with ANSI theme support
- jernejk/AspNetCoreSerilogExample: This is an example of how to create an ASP .NET Core app with Serilog (.NET 5.0)
Showing the top 20 packages that depend on Substantive.Extensions.Logging.
| Packages | Downloads |
|---|---|
|
Substantive.AspNetCore
Package Description
|
10 |
|
Substantive.AspNetCore
Package Description
|
12 |
|
Substantive.AspNetCore
Package Description
|
43 |
|
Substantive.AspNetCore
Package Description
|
91 |
|
Substantive.AspNetCore
Substantive ASP.NET Core package.
|
10 |
|
Substantive.AspNetCore
Substantive ASP.NET Core package.
|
13 |
|
Substantive.AspNetCore
Substantive ASP.NET Core package.
|
20 |
|
Substantive.AspNetCore
Substantive ASP.NET Core package.
|
21 |
|
Substantive.AspNetCore
Substantive ASP.NET Core package.
|
22 |
|
Substantive.AspNetCore
Substantive ASP.NET Core package.
|
24 |
|
Substantive.AspNetCore
Substantive untitled internal package.
|
14 |
|
Substantive.AspNetCore
Substantive untitled internal package.
|
29 |
|
Substantive.AspNetCore
Substantive untitled internal package.
|
31 |
|
Substantive.AspNetCore
Substantive untitled internal package.
|
52 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
11 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
14 |
|
Substantive.Foundation.Backends
A metapackage contains all Substantive backend building blocks.
|
16 |
.NET 9.0
- SeriLogThemesLibrary (>= 1.0.0.2)
- Serilog.AspNetCore (>= 9.0.0)
- Serilog.Enrichers.AspNetCore.HttpContext (>= 1.0.1)
- Serilog.Enrichers.ClientInfo (>= 2.2.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Sensitive (>= 1.7.3)
- Serilog.Expressions (>= 5.0.0)
- Serilog.Formatting.Compact (>= 3.0.0)
- Serilog.Settings.Configuration (>= 9.0.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 6.0.0)
- Serilog.Sinks.Grafana.Loki (>= 8.3.1)
- Serilog.Sinks.OpenTelemetry (>= 4.2.0)
- Serilog.Sinks.Seq (>= 8.0.0)