Repository navigation
Description
In Exceptionless.Log4net 6.2.0, when ApiKey or ServerUrl is set on ExceptionlessAppender or BufferingExceptionlessAppender, the appender creates its own ExceptionlessClient with in-memory storage. Nothing ever processes that client's queue on close or flush, so events logged shortly before the process exits are never sent.
Where
Exceptionless.Net/src/Platforms/Exceptionless.Log4net/ExceptionlessAppender.cs
Lines 12 to 27 in 5792f00
public override void ActivateOptions() { if (String.IsNullOrEmpty(ApiKey) && String.IsNullOrEmpty(ServerUrl)) return; _client = new ExceptionlessClient(config => { if (!String.IsNullOrEmpty(ApiKey) && ApiKey != "API_KEY_HERE") config.ApiKey = ApiKey; if (!String.IsNullOrEmpty(ServerUrl)) config.ServerUrl = ServerUrl; config.UseInMemoryStorage(); // Rely on Logging Rules config.SetDefaultMinLogLevel(Logging.LogLevel.Trace); }); } Exceptionless.Net/src/Platforms/Exceptionless.Log4net/BufferingExceptionlessAppender.cs
Lines 17 to 34 in 5792f00
public override void ActivateOptions() { base.ActivateOptions(); if (String.IsNullOrEmpty(ApiKey) && String.IsNullOrEmpty(ServerUrl)) return; _client = new ExceptionlessClient(config => { if (!String.IsNullOrEmpty(ApiKey) && ApiKey != "API_KEY_HERE") config.ApiKey = ApiKey; if (!String.IsNullOrEmpty(ServerUrl)) config.ServerUrl = ServerUrl; config.UseInMemoryStorage(); // Rely on Logging Rules config.SetDefaultMinLogLevel(Logging.LogLevel.Trace); }); }
For comparison, the NLog target flushes its client:
| protected override void FlushAsync(AsyncContinuation asyncContinuation) { | |
| _client.ProcessQueueAsync().ContinueWith(t => asyncContinuation(t.Exception)); | |
| } |
What happens
- The private client is never started, so it does not register the process-exit handler that
Startup()registers for other clients. - Neither appender overrides
OnCloseorFlush, soLogManager.Shutdown()/LogManager.Flush()do not send queued events. - The queue is only processed by the client's timer (first run after 2 seconds, then every 10 seconds). Events logged in the last few seconds before exit stay in memory and are lost. For
BufferingExceptionlessAppender, the buffer is handed to the client on close, but the client's queue is still never sent. - The client is never disposed either.
Expected
Closing or flushing the appender (for example LogManager.Shutdown()) sends the queued events, and the appender disposes a client it created.
Steps to reproduce
- Configure
ExceptionlessAppenderin log4net with<apiKey value="..." />. - In a console app, log an error and then call
LogManager.Shutdown()and exit. - The event never arrives in Exceptionless.
Suggested fix
In both appenders, override OnClose (calling the base first for the buffering appender so the buffer is submitted) and Flush(int millisecondsTimeout) to call _client.ProcessQueueAsync() and wait up to the timeout, and dispose the client in OnClose when the appender created it.
Activity