Created
May 3, 2020 08:15
-
-
Save sametoz/092850e29f1b505cb6e08161a91ffc33 to your computer and use it in GitHub Desktop.
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
public class LogContextMiddleware | |
{ | |
private readonly RequestDelegate next; | |
public LogContextMiddleware(RequestDelegate next) | |
{ | |
this.next = next; | |
} | |
public Task Invoke(HttpContext context) | |
{ | |
/* | |
LogContext, Serilog'un Context kayıtlarını denetler. | |
PushProperty ile parametreleri çekip, Log mekanizmasına yönlendirebilirsin. | |
İlk parametre Property'nin adını, ikinci parametre ise context'teki property'yi ifade eder. | |
ÖNEMLİ!: Döndürülen property adı, log konfigürasyonundaki sütun ismiyle aynı olmalıdır. | |
*/ | |
LogContext.PushProperty("UserName", context.User.Identity.Name); | |
LogContext.PushProperty("ApiPath", context.Request.Path); | |
return next(context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment