Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify minimum level for specific request #2047

Open
MartinKosicky opened this issue Apr 11, 2024 · 1 comment
Open

Modify minimum level for specific request #2047

MartinKosicky opened this issue Apr 11, 2024 · 1 comment

Comments

@MartinKosicky
Copy link

Is your feature request related to a problem? Please describe.
We have microservices that have milions of requests per minute, however we do every 5 minutes some end-2-end monitorings. Because of the ammount of logs we would generate we cannot afford to have verbosity lower than Warning. However these monitorings tend to fail from time to time, and these monitorings have some special header that when we process a request we know its from monitoring. For such request issued by monitoring it would be helfpul to have a diferent log level for example Information. Otherwise I have to create a new logger with a specific category based on if this is monitoring

Describe the solution you'd like
Some ability to modify the log level for some scope

Describe alternatives you've considered
Initialize a logger with diferent category

@nblumhardt
Copy link
Member

When you set up Serilog, you'll somewhere be doing an AddSerilog() or UseSerilog() call to wire it into MEL, and/or setting Log.Logger to an ILogger instance.

You may be able to get what you're after by wrapping this root logger in your own custom type, which would need to implement ILogger, IDisposable, and IAsyncDisposable.

All methods would forward to the wrapped logger, except IsEnabled(LogEventLevel), which would perform some custom check based on an AsyncLocal, and ForContext(), which would use the same logic as IsEnabled() to detect that the current request/activity/whatever is a sampled one, and in those cases, wrap the results of calling ForContext() on the inner logger in an additional instance of your wrapper type before returning the result.

Hope this helps!
Nick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants