mthamil / aspnetcore.serilog.requestloggingmiddleware Goto Github PK
View Code? Open in Web Editor NEWMiddleware for ASP.NET Core that uses Serilog to log requests.
License: Apache License 2.0
Middleware for ASP.NET Core that uses Serilog to log requests.
License: Apache License 2.0
Application startup exception: System.InvalidOperationException: Unable to resolve service for type 'Serilog.ILogger' while attempting to activate 'AspNetCore.Serilog.RequestLoggingMiddleware.SerilogRequestMiddleware'.
Anything we need to register for the middle to work?
Currently messagetemplate is hardcoded
private const string MessageTemplate = "HTTP {Method} to '{Path}' responded with {StatusCode} in {Elapsed:0.0000} ms";
Changing this would enable localization and more customization.
For example, using {Elapsed:0.00} ms
instead of {Elapsed:0.0000} ms
would be useful as it's less noisy IMHO
As in the topic.
I can see ILogger is always used. I need a way to provider other logger instance than ILogger so that I can configure separate loggers for web request, maintenance, etc.
Just wondering how I'd would use this. Thanks!
I added a LogContext property, CorrelationId, which am able to log using the output template:
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} | {Level:u3} | {CorrelationId} | {Message:lj}{NewLine}{Exception}"
Most of the log lines show the CorrelationId. e.
2021-05-20 10:18:19.971 | INF | CID: 12345C12 | Executed endpoint ...
2021-05-20 10:18:19.975 | INF | CID: 12345C12 | HTTP GET /api/v1/model/search?...responded 200 in 2396.5086 ms
2021-05-20 10:18:19.977 | DBG | CID: 12345C12 | [Response]: 200: {...}
The summary line from this middleware does not log the CorrelationId
2021-05-20 10:18:19.981 | INF | | Request finished in 2411.9684ms 200 application/json; charset=utf-8
Is there a way for this Middleware to log this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.