Closed ogaca-dd closed 3 years ago
@yuwaMSFT2,
Thanks a lot for the code review. I have updated the code based on your comments but there is a corner case I need to fix before pushing my commits.
@yuwaMSFT2,
I have updated the PR, let me know if it suits your needs.
Thank you @ogaca-dd! Overall looks good to me!
Would it be an idea to collect exceptions as an aggregated exception and pass that to the callback as a property on the custom exception? Seems like it would be useful to know why the logging failed.
Add an error handler when an exception occurs.
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.DatadogLogs(API_KEY, exceptionHandler: e => { var cannotSendLogEventException = e as CannotSendLogEventException; if (cannotSendLogEventException != null) { Console.WriteLine($"ERROR: {cannotSendLogEventException} LogEvents Count: {cannotSendLogEventException.LogEvents.Count()}"); } }) .CreateLogger(); Log.Information("Test serilog"); Log.CloseAndFlush(); }
Is there a way in the exception handler to then get the logger for the current context and log a shorter exception? I was thinking in the case of payload being too large logging an error back in to datadog to let us know the caller.
Add an error handler when an exception occurs.