Description
Combining this with an audit log Serilog configuration, exceptions are swallowed and never emitted back to the caller as would be expected.
Steps to reproduce:
- Set up an audit logging configuration for Serilog which is purposefully mal-configured (for example, using the MS SQL Server sink to log events to a non-existent database table).
- Implement logging using Microsoft.Extensions.Logging.Abstractions and an ILogger using this library.
- Emit a log event (
logger.LogInformation("test");
)
Expected behaviour: Exception to be thrown at the call to LogInformation()
.
Actual behaviour:
- No exception is thrown
- The underlying exception is visible in Serilog's SelfLog
It looks like the culprit of this behaviour is here:
Apologies for posting this up as an issue with no accompanying pull request but that's somewhat down to time constraints right now and largely because I'm not sure what the implications of changing this are likely to be. The obvious fix for this specific problem as I see it would just be to get rid of the try/catch block entirely and assume that if an exception is encountered, it's something we care about. However I am aware that my scenario is probably quite specific (it seems like audit logging is far less common than regular logging where errors should be ignored) and my proposed 'fix' might well create new problems for people in other scenarios. And/or not account for other possible causes of exceptions which don't relate to the underlying Serilog logger having emitted them.
Let me know if I can add anything more to clarify and/or if I'm barking up the wrong tree here with this.