Skip to content

No exceptions emitted when generated by faulty audit log configuration #209

Closed
@markembling

Description

@markembling

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:

  1. 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).
  2. Implement logging using Microsoft.Extensions.Logging.Abstractions and an ILogger using this library.
  3. 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:

try
{
Write(level, eventId, state, exception, formatter);
}
catch (Exception ex)
{
SelfLog.WriteLine($"Failed to write event through {typeof(SerilogLogger).Name}: {ex}");
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions