Code Coverage by Clover.NET

AsyncWrapper seems to ignore the overflowAction...

View: New views
3 Messages — Rating Filter:   Alert me  

AsyncWrapper seems to ignore the overflowAction...

by NLog Convert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here's my target element:

<target name="MyTarget" type="AsyncWrapper" batchSize="100" queueLimit="10000" overflowAction="Block">
  <target type="MyOwnDBTarget"/>
</target>

I hammer on this with multiplethreads.  When I compare this to the non-buffered, synchronous MyOwnDBTarget, the AsyncWrapper one "loses" about half of the log messages.  It doesn't seem to matter how I vary the parameters:   I make the queueLimit very big (50000) or if the overflowAction is "Grow", or batchSize changes.  I've also played with the timeToSleepBetweenBatches, but it always seems to drop log messages.

Re: AsyncWrapper seems to ignore the overflowAction...

by Jaroslaw_Kowalski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

NLog Convert wrote:
Here's my target element:

<target name="MyTarget" type="AsyncWrapper" batchSize="100" queueLimit="10000" overflowAction="Block">
  <target type="MyOwnDBTarget"/>
</target>

I hammer on this with multiplethreads.  When I compare this to the non-buffered, synchronous MyOwnDBTarget, the AsyncWrapper one "loses" about half of the log messages.  It doesn't seem to matter how I vary the parameters:   I make the queueLimit very big (50000) or if the overflowAction is "Grow", or batchSize changes.  I've also played with the timeToSleepBetweenBatches, but it always seems to drop log messages.
That's interesting - I have never seen this and NLog/async is used in heavily-multithreaded scenarios.
Can you enable internal logging to find out:

<nlog internalLogFile="c:\path\to\some\file.txt" internalLogLevel="Debug">
...
</nlog>

Please send the log files to jaak - at - jkowalski - dot - net

Re: AsyncWrapper seems to ignore the overflowAction...

by NLog Convert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, what appears to be happening is that my program ends without calling flush().

So, my question is:  is there a way to tell nlog to flush the queue when shutting down?

In my simple console test app, I can call flush at the end of main, and everything works hunky dory.  however, in the real app(s), I register for AppDomain.CurrentDomain.DomainUnload or AppDomain.CurrentDomain.ProcessExit events in order to know when to call flush.  The problem is that if there are a lot of entries left in the queue by the time the main thread is leaving the main function, these events are never raised, so I never call flush, and the remaining entries are discarded.  If the queue is empty, then the events ARE raised.  --not sure what's preventing this event.

A work around:  If I wrap my target in an AutoFlush wrapper, no events are lost, but I essentially lose any advantage of batching my database writes.  --it is most often writing 1 or 2 events at a time, regardless of the timeToSleepBetweenBatches.

From the last line of the internal nlog file, Closing target NLog.Targets.Wrappers.AsyncTargetWrapper (DBTarget).  It apparently closes it without first flushing the queue.

Any help is appreciated.
NLogFile.txt