1
Vote

Async Wrapper does not seem to be getting called

description

Hi,

One of the projects that I've joined is using NLog. Unfortunately some of the logging is taking longer than expected so I'm trying to write to the log asynchronously.

If I put async=true into targets then it is writing asynchronously and doesn't impede the main thread. However if I remove this and use AsyncWrapper then the write is slow again.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <extensions>
      <add assembly="NLog.Extended"/>
    </extensions>
    <targets>
      <target name="AsyncInformation" xsi:type="AsyncWrapper" overflowAction="Block" queueLimit="1000000" batchSize="1000" timeToSleepBetweenBatches="0">
        <target name="Information"
        xsi:type="File"
        fileName="C:\Logs\InformationLog.txt"
        archiveFileName="C:\Logs\Archive\InformationLog.{#}.txt"
        archiveAboveSize = "262144"
        archiveNumbering="Rolling"
        maxArchiveFiles="30"
        layout="${message}"
                concurrentWrites="true"/>
      </target>
      <target name="AsyncException" xsi:type="AsyncWrapper" overflowAction="Block" queueLimit="1000000" batchSize="1000" timeToSleepBetweenBatches="0">
        <target name="Exception"
          xsi:type="File"
          fileName="C:\Logs\ExceptionLog.txt"
          archiveFileName="C:\Logs\Archive\ExceptionLog.{#}.txt"
          archiveAboveSize = "262144"
          archiveNumbering="Rolling"
          maxArchiveFiles="30"
          layout="${message}" concurrentWrites="true"/>
      </target>
    </targets>
    <rules>
      <logger name="*" minlevel="Info" maxlevel="Info" writeTo="AsyncInformation"/>
      <logger name="*" minlevel="Error" maxlevel="Error" writeTo="AsyncException"/>
    </rules>
  </nlog>
The logging code is:
            _logger = NLog.LogManager.GetLogger("MyLogger");

            ExceptionLogMessage newLogMessage = new ExceptionLogMessage(description, e,callingFunction);
            _logger.Error(newLogMessage.Serialise);
I've tried different settings in AsyncWrapper, even the default, which I presume is what async=true is using but nothing seems to be produce the same result as async=true does. Which suggests to me that I'm not registering the AsyncWrapper correctly - but I can't find what I'm doing wrong.

Any suggestions?

Using NLog v2.0

Kind regards
Sidharth

comments

sidharthnayyar wrote Mar 17, 2015 at 9:28 AM

Hi,

I've found the cause of the issue. There was another rule which was getting set which was causing the issue. I "async-ed" that and it's working similar to the async=true now.

Kind regards