log4net appenders never flush their client, so events are lost at shutdown

Aperta Adatta ai principianti
#390 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

Leggi ExceptionlessAppender.cs e BufferingExceptionlessAppender.cs nelle posizioni collegate, quindi confronta la gestione dell’arresto con ExceptionlessTarget.cs. Segui il modo in cui ciascun appender crea il proprio client e in cui la chiusura del buffer invia gli eventi; il lavoro è completato quando la chiusura o lo svuotamento elabora gli eventi in coda entro il timeout e rilascia solo un client creato dall’appender.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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

For comparison, the NLog target flushes its client: https://github.com/exceptionless/Exceptionless.Net/blob/5792f00d175f94a35fe0559c8e9999234a8163be/src/Platforms/Exceptionless.NLog/ExceptionlessTarget.cs#L96-L98

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 OnClose or Flush, so LogManager.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

  1. Configure ExceptionlessAppender in log4net with <apiKey value="..." />.
  2. In a console app, log an error and then call LogManager.Shutdown() and exit.
  3. 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.

Lingua principale
C#
Stelle
573
Fork
143
Merge medio
5g 9h
PR unite (30g)
1

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di exceptionless/Exceptionless.Net

Tutte le issue di exceptionless/Exceptionless.Net

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.