【发布时间】:2019-08-21 09:53:00
【问题描述】:
我用于记录 Microsoft.Extensions.Logging 和 NLog。日志被写入 Elasticsearch。当我使用 Kibana 查看我的日志时,我的所有日志都写在 UT,这意味着与我的本地时间 (-zone) MET 有两个小时不同。我想查看我在 Kibana 的当地时间的日志。 如何调整日志记录的时区?
我添加了 NLog.config:
<nlog autoReload="true" throwExceptions="false"
internalLogLevel="Info" internalLogFile="NLogError.log"
xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="Logfile" xsi:type="File"
fileName="${basedir}dap.log"
layout="${longdate} ${level} ${callsite} -> ${message} ${exception:format=Message,StackTrace}"
archiveFileName="${basedir}/archives/log.{#}.log"
archiveEvery="Day"
archiveNumbering="Rolling"
maxArchiveFiles="14"
keepFileOpen="false"
/>
<target xsi:type="Network"
name="CentralLog"
newLine ="false"
maxMessageSize="65000"
connectionCacheSize="5"
encoding="utf-8"
keepConnection="false"
maxQueueSize="100"
address="tcp://myurl.org:5544"
onOverflow="Split">
<layout type="JsonLayout">
<attribute name="machinename" layout="${machinename}" />
<attribute name="level" layout="${level:upperCase=true}" />
<attribute name="processname" layout="${processname}" />
<attribute name="processid" layout="${processid}" />
<attribute name="sendertimestamp" layout="${date:universalTime=true:format=yyyy-MM-ddTHH\:mm\:ss.fff}" />
<attribute name="module" layout="dhp DataPickerApi ${logger}" />
<attribute name="message" layout="${message}" />
<attribute name="exception" layout="${exception}" />
<attribute name="activityId" layout="${activityId}" />
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="Logfile" />
<logger name="*" minlevel="Trace" writeTo="CentralLog"/>
</rules>
</nlog>
【问题讨论】:
-
您的 NLog 配置中可能有一个选项。请分享您的 NLog 配置
-
如何将日志事件从 NLog 转发到 Elasticsearch?你用filebeat还是nuget.org/packages/NLog.Targets.ElasticSearch?
-
@Julian 我将 NLog.config 添加到我最初的问题中。我尝试使用 或 这行在节省的时间并没有什么不同。
-
@RolfKristensen 我使用 nuget 包 NLog。 var logger = new LoggerFactory().AddNLog().CreateLogger
();
标签: elasticsearch logging timezone nlog