NLog: Custom target with async attribute get incorrect timestamp and order of logs
NLog version: 4.6.5
Platform: WebApi 2.1 .net47
Current NLog config
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target name="graylogt" xsi:type="GraylogHttp" facility="WebApi" graylogServer="http://graylog" graylogPort="12201">
<parameter name="current_user" layout="${aspnet-user-identity}" />
<parameter name="exception_type" layout="${exception:Type}" />
<parameter name="request" layout="${aspnet-request-method} ${aspnet-request-url}" />
<parameter name="site" layout="${iis-site-name} ${aspnet-appbasepath}" />
<parameter name="request_body" layout="${onexception:${aspnet-request-posted-body}:when=level>=LogLevel.Error}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="debug" writeTo="graylogt" />
</rules>
</nlog>
Hi, I use a https://github.com/dustinchilson/NLog.Targets.GraylogHttp for graylog. In order to don’t block the thread for logging I use an async attribute. But logs have incorrect timestamps and order(compare to sync mode). I can’t use “sync” logs, because every log operation takes 0.2 sec.
- What is the current result?
Incorrect order and timestamp of logs
- What is the expected result?
Correct order and timestamps
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 41 (22 by maintainers)
Created PR https://github.com/farzadpanahi/NLog.GelfLayout/pull/14 for you. Introduces a new setting
FixDuplicateTimestamp
(Default =False
)Can handle bursts of 9 unique timestamps within the same millisecond:
So my final nlog-config is
and here is my graylog input
Happy the problem has been resolved. Could you post your final nlog-config for others to witness?
What happens if you configure
keepConnection="True"
andlineEnding="Null"
?