Skip to content

Instantly share code, notes, and snippets.

@CoreProgramm
Last active April 30, 2020 12:36
Show Gist options
  • Save CoreProgramm/b111c739c7b2cf95292902f5632b60da to your computer and use it in GitHub Desktop.
Save CoreProgramm/b111c739c7b2cf95292902f5632b60da to your computer and use it in GitHub Desktop.
CustomLoggerMiddleware
public class CustomLoggerMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger _logger;
public CustomLoggerMiddleware(RequestDelegate next, ILoggerFactory logFactory)
{
_next = next;
_logger = logFactory.CreateLogger("MyMiddleware");
_logger.LogInformation("MyMiddleware is Started");
}
public async Task Invoke(HttpContext httpContext)
{
_logger.LogInformation("MyMiddleware is executing..");
await _next.Invoke(httpContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment