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

Routing log events by event type to be queued or not #78

Closed
sfiodorov opened this issue Jan 17, 2022 · 1 comment
Closed

Routing log events by event type to be queued or not #78

sfiodorov opened this issue Jan 17, 2022 · 1 comment

Comments

@sfiodorov
Copy link

Hi.
Im using Redis sync to transfer app logs to elastic.
When using your wonderful nuget there is a chance when a fatal exception has happened and the process crashed (like OutOfMemory) but the log entry has not been processed yet since it was queued and it was additional logs to process before that.
My idea is to send fatal and error messages via regular Redis sync and less important messages via Async. The order is not important since the target organizes the logs by log datetime field.
So I prepared something like this:

 bool IsLogEventCritical(LogEvent logEvent) => logEvent.Level < LogEventLevel.Information;
                loggerConfiguration
                    // route non critical logs directly to queue before redis
                    .WriteTo
                    .Async(configureAsync =>
                        configureAsync.Conditional(x => !IsLogEventCritical(x),
                            loggerRedisAsyncConfiguration => loggerRedisAsyncConfiguration.Redis(redisConnectionConfig)))
                    // route critical logs directly to redis
                    .WriteTo
                    .Conditional(IsLogEventCritical,
                        loggerRedisConfiguration => loggerRedisConfiguration.Redis(redisConnectionConfig));

Is this a good practice to ensure that critical logs are delivered in case of application crash or not rejected from queue because of queue limit is reached?

@nblumhardt
Copy link
Member

This looks fine to me, thanks for posting the example, hope it worked well for you! 👍

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

No branches or pull requests

2 participants