OnException Wrapper: strange performance behavior

Skip to first unread message

Edi Tomat

Jul 24, 2017, 11:04:53 AM7/24/17
to NLog-Users
  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=
    //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";

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

Rolf Kristensen

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

Reply all
Reply to author
0 new messages