如何设置当前的日志记录时间(区域)?

时间:2019-08-21 09:53:00

标签: elasticsearch logging timezone nlog

我用于记录 Microsoft.Extensions.Logging和NLog 。日志将写入 Elasticsearch 。当我使用 Kibana 查找日志时,我所有的日志都写在UT,这意味着与我的本地时间(-区域)MET有两个不同的层次。我想看看我在基巴纳当地时间的日志。 如何调整日志记录的时区?

我添加了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>

2 个答案:

答案 0 :(得分:2)

不使用#include <iostream> #include <string> #include <string_view> struct A { void f( const char *s ) const { std::cout << "A::f( " << s << " )\n"; } }; struct B { void f( const std::string &s ) const { std::cout << "B::f( " << s << " )\n"; } }; template <typename... Bases> struct C : Bases... { using Bases::f...; }; int main() { C<A, B>().f( std::string_view( "Hello" ) ); // or std::string_view s( "Hello" ); C<A,B>().f( s ); } 吗? 所以代替这个:

universalTime=true

使用此:

<attribute name="sendertimestamp" 
           layout="${date:universalTime=true:format=yyyy-MM-ddTHH\:mm\:ss.fff}" />  

答案 1 :(得分:0)

您可以在Kibana网站中设置时区。

设置->高级---> DateFormat:tz

以获取更多信息:https://www.elastic.co/guide/en/kibana/current/advanced-options.html