Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit d4bf727

Browse files
committed
Aggiunta documentazione SERILOG
1 parent 741f283 commit d4bf727

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

src/NET6CustomLibrary/Docs/.gitkeep

Whitespace-only changes.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Serilog configuration
2+
3+
4+
## Configuration to add to the appsettings.json file
5+
6+
```json
7+
"Serilog": {
8+
"MinimumLevel": "Warning",
9+
"WriteTo": [
10+
{
11+
"Name": "Console",
12+
"Args": {
13+
"outputTemplate": "{Timestamp:HH:mm:ss}\t{Level:u3}\t{SourceContext}\t{Message}{NewLine}{Exception}"
14+
}
15+
},
16+
{
17+
"Name": "File",
18+
"Args": {
19+
"path": "Logs/log.txt",
20+
"rollingInterval": "Day",
21+
"retainedFileCountLimit": 14,
22+
"restrictedToMinimumLevel": "Warning",
23+
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
24+
}
25+
}
26+
]
27+
}
28+
```
29+
30+
31+
## Registering services at Startup
32+
33+
```csharp
34+
public Startup(IConfiguration configuration)
35+
{
36+
Configuration = configuration;
37+
}
38+
39+
public IConfiguration Configuration { get; }
40+
41+
public void ConfigureServices(IServiceCollection services)
42+
{
43+
services.AddSerilogServices();
44+
}
45+
46+
//OMISSIS
47+
48+
public void Configure(WebApplication app)
49+
{
50+
app.AddSerilogConfigureServices();
51+
}
52+
```
53+
54+
55+
## Registering services at Program
56+
57+
```csharp
58+
public static void Main(string[] args)
59+
{
60+
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
61+
62+
builder.AddSerilogOptionsBuilder();
63+
64+
Startup startup = new(builder.Configuration);
65+
66+
//OMISSIS
67+
}
68+
```
69+
70+
71+
## Example of use in a web api controller
72+
73+
```csharp
74+
[ApiController]
75+
[Route("api/[controller]")]
76+
public class EmailController : ControllerBase
77+
{
78+
private readonly ILoggerService loggerService;
79+
80+
public EmailController(ILoggerService loggerService)
81+
{
82+
this.loggerService = loggerService;
83+
}
84+
85+
//OMISSIS
86+
}
87+
```

0 commit comments

Comments
 (0)