OnException Wrapper: strange performance behavior

13 views
Skip to first unread message

Edi Tomat

unread,
Jul 24, 2017, 11:04:53 AM7/24/17
to NLog-Users
Dears,
  Running performance test on different Nlog configuration I've found a strange behavior of the OnException Wrapper...
It is deigned to call the Inner Layout only if a exception is present on the LogEvent passed to the wrapper, so theoretically the InnerLayout should not have any performance impact if the exception is not present...
but i found that it really have a performance impact..

Considering the Target (config in  source code)

//Configure Targets
Target synchtarget = new FileTarget
{
    Name = "appfile",
    //SLOW   Layout = @"${Level} ${date:format=MM-dd HH\:mm\:ss} - ${message}${onexception:inner=${newline}${exception:innerFormat=Message,Type,StackTrace,Data:maxInnerExceptionLevel=5:format=Message,Type,StackTrace,Data:separator=
:exceptionDataSeparator=
}${newline}${callsite:className=True:fileName=True:includeSourcePath=False:methodName=True}}",
    //FAST   Layout = @"${Level} ${date:format=MM-dd HH\:mm\:ss} - ${message}",
    FileName = @"..\Output\Log\hardCodedFileName.log",
    ArchiveFileName = @".\Log\History\hardCodedFileName__${date:format=yyyy-MM-dd__HH-mm-ss}.{#}.log",
    ArchiveAboveSize = 10485760,
    MaxArchiveFiles = 1000,
    ConcurrentWrites = false
};
 
Target realTarget = new AsyncTargetWrapper(synchtarget, 500000, AsyncTargetWrapperOverflowAction.Discard);
realTarget.Name = "realtarget";
config.AddTarget(realTarget);

running a loop of 50000 logs of that target and calculating the throughput (mgs/sec), just changing the layout config I obtain:
SLOW Layout (with OnException): 250 mg/sec
FAST Layout (without OnException): 11609 mg/sec

(I've compared the resulting log files and are the same, so both Layouts are logging the same)


Do you have any idea? 
Maybe I'm doing somethting wrong with the config...for sure not with the speed measurement, that is done in same way for both cases


my dev environment: VS2015 pro SP3 and Nlog 4.4.11
Edi

Rolf Kristensen

unread,
Aug 9, 2017, 3:28:15 PM8/9/17
to NLog-Users
Sounds like a duplicate of:

https://github.com/NLog/NLog/issues/2225

-Rolf
Reply all
Reply to author
Forward
0 new messages