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

Commit 924b4e9

Browse files
committed
Documentazione Serilog aggiornata #26 #27
closes #26 closes #27
1 parent 1509cf8 commit 924b4e9

File tree

2 files changed

+162
-6
lines changed

2 files changed

+162
-6
lines changed

src/NET6CustomLibrary/Docs/README-Serilog.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
```json
77
"Serilog": {
8-
"MinimumLevel": "Warning",
8+
"MinimumLevel": "Debug",
99
"WriteTo": [
1010
{
1111
"Name": "Console",
@@ -73,15 +73,36 @@ public static void Main(string[] args)
7373
```csharp
7474
[ApiController]
7575
[Route("api/[controller]")]
76-
public class EmailController : ControllerBase
76+
public class PeopleController : ControllerBase
7777
{
78-
private readonly ILoggerService loggerService;
78+
private readonly ILoggerService logger; //required using NET6CustomLibrary.Serilog.Services;
7979
80-
public EmailController(ILoggerService loggerService)
80+
public PeopleController(ILoggerService logger)
8181
{
82-
this.loggerService = loggerService;
82+
this.logger = logger;
83+
}
84+
85+
[HttpGet("people")]
86+
public async Task<IActionResult> GetPeople()
87+
{
88+
//OMISSIS
89+
90+
logger.SaveLogInformation("YOUR INFORMATION MESSAGE");
91+
92+
//OMISSIS
8393
}
8494

8595
//OMISSIS
8696
}
87-
```
97+
```
98+
99+
100+
## Types of loggers provided in the ILoggerService class
101+
102+
- CRITICAL
103+
- ERROR
104+
- WARNING
105+
- INFORMATION
106+
- DEBUG
107+
108+
<b>Note:</b> Required using NET6CustomLibrary.Serilog.Services of the NET6CustomLibrary Nuget package
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Serilog configuration with SEQ platform
2+
3+
4+
## Configuration to add to the appsettings.json file (Writing logs to console, to txt file and to SEQ platform)
5+
6+
<b>Note:</b> If the logs must be saved only on SEQ, comment out and/or delete the part of the configuration linked to the FILE and CONSOLE sections.
7+
8+
The minimum level of traced logs is DEBUG.
9+
10+
```json
11+
"Serilog": {
12+
"MinimumLevel": "Debug",
13+
"WriteTo": [
14+
{
15+
"Name": "Console",
16+
"Args": {
17+
"outputTemplate": "{Timestamp:HH:mm:ss}\t{Level:u3}\t{SourceContext}\t{Message}{NewLine}{Exception}"
18+
}
19+
},
20+
{
21+
"Name": "File",
22+
"Args": {
23+
"path": "Logs/log.txt",
24+
"rollingInterval": "Day",
25+
"retainedFileCountLimit": 14,
26+
"restrictedToMinimumLevel": "Information",
27+
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog",
28+
"outputTemplate": "{Timestamp:HH:mm:ss}\t{Level:u3}\t{SourceContext}\t{Message}{NewLine}{Exception}"
29+
}
30+
},
31+
{
32+
"Name": "Seq",
33+
"Application": "Sample API",
34+
"Args": {
35+
"serverUrl": "http://server-seq:5341",
36+
"ApiKey": "YOUR-APIKEY",
37+
"restrictedToMinimumLevel": "Information",
38+
"outputTemplate": "{Timestamp:HH:mm:ss}\t{Level:u3}\t{SourceContext}\t{Message}{NewLine}{Exception}"
39+
}
40+
}
41+
]
42+
}
43+
```
44+
45+
46+
## Registering services at Startup
47+
48+
```csharp
49+
public Startup(IConfiguration configuration)
50+
{
51+
Configuration = configuration;
52+
}
53+
54+
public IConfiguration Configuration { get; }
55+
56+
public void ConfigureServices(IServiceCollection services)
57+
{
58+
services.AddSerilogSeqServices();
59+
}
60+
61+
//OMISSIS
62+
63+
public void Configure(WebApplication app)
64+
{
65+
//OMISSIS
66+
67+
app.AddSerilogConfigureServices();
68+
69+
//OMISSIS
70+
}
71+
```
72+
73+
74+
## Registering services at Program
75+
76+
```csharp
77+
public static void Main(string[] args)
78+
{
79+
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
80+
81+
builder.AddSerilogOptionsBuilder();
82+
83+
Startup startup = new(builder.Configuration);
84+
85+
//OMISSIS
86+
}
87+
```
88+
89+
90+
## Example of use in a web api controller
91+
92+
```csharp
93+
[ApiController]
94+
[Route("api/[controller]")]
95+
public class PeopleController : ControllerBase
96+
{
97+
private readonly ILoggerService logger; //required using NET6CustomLibrary.Serilog.Services;
98+
99+
public PeopleController(ILoggerService logger)
100+
{
101+
this.logger = logger;
102+
}
103+
104+
[HttpGet("people")]
105+
public async Task<IActionResult> GetPeople()
106+
{
107+
//OMISSIS
108+
109+
logger.SaveLogInformation("YOUR INFORMATION MESSAGE");
110+
111+
//OMISSIS
112+
}
113+
114+
//OMISSIS
115+
}
116+
```
117+
118+
119+
## Docker SEQ
120+
121+
An example of a Docker configuration of SEQ can be found [here](https://github.com/AngeloDotNet/Docker.Application/tree/master/Seq).
122+
123+
For SEQ (docker version) the first boot occurs without any form of active login.
124+
After the docker is active, navigate to the SETTINGS > USERS section to enable authentication to access the dashboard.
125+
126+
127+
## Types of loggers provided in the ILoggerService class
128+
129+
- CRITICAL
130+
- ERROR
131+
- WARNING
132+
- INFORMATION
133+
- DEBUG
134+
135+
<b>Note:</b> Required using NET6CustomLibrary.Serilog.Services of the NET6CustomLibrary Nuget package

0 commit comments

Comments
 (0)