Conditional logging by Serilog in C#

asp.net-core, asp.net-core-mvc, c#, serilog

Solution

No, this isn't built into the Serilog sinks you have described.

Enabling all three sinks concurrently achieves roughly the same thing - you could avoid additional latency by writing through Serilog.Sinks.Async if the file I/O is a concern.

Problem

There is a Asp.Net Core project requirement that we need to log errors, warnings, information, exceptions, etc. to the streams below: 1) A SQL Server table. 2) During logging, if SQL Server database suddenly becomes unavailable, we'd like to continue logging by writing log entries to a shared network folder. 3) Again, if during logging, the shared network folder becomes unavailable, then we want to continue logging to a local folder. Is this scenario something that Serilog (https://serilog.net/) can help us to achieve?

Original source