-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imroved Logging - added CorrelationId to logs
- Loading branch information
Showing
6 changed files
with
119 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
AirportAutomation/AirportAutomationInfrastructure/Middlewares/RequestLogContextMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Serilog.Context; | ||
|
||
namespace AirportAutomation.Infrastructure.Middlewares | ||
{ | ||
public class RequestLogContextMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
public RequestLogContextMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public Task InvokeAsync(HttpContext context) | ||
{ | ||
using (LogContext.PushProperty("CorrelationId", context.TraceIdentifier)) | ||
{ | ||
return _next(context); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,53 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Error", | ||
"Microsoft.AspNetCore": "Warning", | ||
"Microsoft.EntityFrameworkCore.Database.Command": "Information", | ||
"Microsoft.EntityFrameworkCore": "Error", | ||
"AirportAutomationApi": "Error" | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Information", | ||
"Override": { | ||
"Microsoft": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], | ||
"WriteTo": [ | ||
{ | ||
"Name": "Console", | ||
"Args": { | ||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {CorrelationId} {Message}{NewLine}{Exception}" | ||
} | ||
}, | ||
{ | ||
"Name": "File", | ||
"Args": { | ||
"path": "Logs/AirportAutomationAPI-.txt", | ||
"rollingInterval": "Day", | ||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {CorrelationId} {Message}{NewLine}{Exception}" | ||
} | ||
} | ||
], | ||
"Filter": [ | ||
{ | ||
"Name": "ExpressionFilter", | ||
"Args": { | ||
"expression": "Level >= Information" | ||
} | ||
}, | ||
{ | ||
"Name": "ExpressionFilter", | ||
"Args": { | ||
"expression": "Level >= Warning" | ||
} | ||
} | ||
] | ||
}, | ||
"AllowedHosts": "*", | ||
"ConnectionStrings": { | ||
"Default": "Data Source=DESKTOP-JENEFBJ\\SQLEXPRESS;Initial Catalog=AirportАutomation;Integrated Security=True;TrustServerCertificate=True;" | ||
}, | ||
"PageSettings": { | ||
"maxPageSize": 10 | ||
}, | ||
"Authentication": { | ||
"SecretForKey": "This is a sample secret key - please don't use in production environment.", | ||
"Issuer": "https://localhost:7107", | ||
"Audience": "https://localhost:7107" | ||
} | ||
"PageSettings": { | ||
"maxPageSize": 10 | ||
}, | ||
"Authentication": { | ||
"SecretForKey": "This is a sample secret key - please don't use in production environment.", | ||
"Issuer": "https://localhost:7107", | ||
"Audience": "https://localhost:7107" | ||
} | ||
} |