zoukankan      html  css  js  c++  java
  • NLog.Targets.ElasticSearch

    The Elasticsearch target works best with the BufferingWrapper target applied.

    By default the target assumes an Elasticsearch node is running on the localhost on port 9200.

    See wiki for parameters.

    <nlog>
      <extensions>
        <add assembly="NLog.Targets.ElasticSearch"/>
      </extensions>
      <targets>
        <target name="elastic" xsi:type="BufferingWrapper" flushTimeout="5000">
          <target xsi:type="ElasticSearch"/>
        </target>
      </targets>
      <rules>
        <logger name="*" minlevel="Info" writeTo="elastic" />
      </rules>
    </nlog>

    Versions

    Versioning follows elasticsearch versions. E.g.

    VersionElasticsearch VersionNLog Version
    7.x 7.x 4.6.x
    6.x 6.x 4.5.x

    Unhandled Exception: System.TypeInitializationException: The type initializer for 'NLogTest.Program' threw an exception. ---> NLog.NLogConfigurationException: Exception when parsing C:Usersclusource eposNLogTestNLogTestinDebugNLog.config. ---> NLog.NLogConfigurationException: Target 'elastic' not found for logging rule: *.
    at NLog.Config.LoggingConfigurationParser.ParseLoggingRuleTargets(String writeTargets, LoggingRule rule)
    at NLog.Config.LoggingConfigurationParser.ParseRuleElement(ILoggingConfigurationElement loggerElement)
    at NLog.Config.LoggingConfigurationParser.ParseRulesElement(ILoggingConfigurationElement rulesElement, IList`1 rulesCollection)
    at NLog.Config.LoggingConfigurationParser.LoadConfig(ILoggingConfigurationElement nlogConfig, String basePath)
    at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(ILoggingConfigurationElement nlogElement, String filePath, Boolean autoReloadDefault)
    at NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String filePath, Boolean autoReloadDefault)
    at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
    --- End of inner exception stack trace ---
    at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
    at NLog.Config.XmlLoggingConfiguration..ctor(XmlReader reader, String fileName, LogFactory logFactory)
    at NLog.Config.LoggingConfigurationFileLoader.LoadXmlLoggingConfiguration(XmlReader xmlReader, String configFile, LogFactory logFactory)
    at NLog.Config.LoggingConfigurationFileLoader.LoadXmlLoggingConfigurationFile(LogFactory logFactory, String configFile)
    at NLog.Config.LoggingConfigurationFileLoader.TryLoadLoggingConfiguration(LogFactory logFactory, String configFile, LoggingConfiguration& config)
    at NLog.Config.LoggingConfigurationFileLoader.TryLoadFromFilePaths(LogFactory logFactory, String filename)
    at NLog.Config.LoggingConfigurationFileLoader.Load(LogFactory logFactory, String filename)
    at NLog.Config.LoggingConfigurationWatchableFileLoader.Load(LogFactory logFactory, String filename)
    at NLog.LogFactory.get_Configuration()
    at NLog.LogFactory.GetLoggerThreadSafe(String name, Type loggerType)
    at NLog.LogManager.GetCurrentClassLogger()
    at NLogTest.Program..cctor() in C:Usersclusource eposNLogTestNLogTestProgram.cs:line 10
    --- End of inner exception stack trace ---
    at NLogTest.Program.Main(String[] args)

    手动配置

      var targetName = "elastic";
                    var target = LogManager.Configuration.FindTargetByName(targetName);
                    if (target is BufferingTargetWrapper bufferingTargetWrapper)
                    {
                        if (bufferingTargetWrapper.WrappedTarget is ElasticSearchTarget elasticSearchTarget)
                        {
                            Console.WriteLine(elasticSearchTarget.Uri);
                            Console.WriteLine(elasticSearchTarget.Index);
                            //elasticSearchTarget.Uri = "http://172.31.211.17:9200/";
                            //elasticSearchTarget.Index = "logstash-20200708-001";
                        }
                    }
  • 相关阅读:
    trident介绍
    Effective TensorFlow Chapter 4: TensorFlow中的广播Broadcast机制【转】
    tslib移植笔记(1)【转】
    jz2440-linux3.4.2-kernel移植【学习笔记】【原创】
    Linxu内核版本号后面多出字符串或者+号【学习笔记】
    向linux内核版本号添加字符/为何有时会自动添加"+"号或者"xxx-dirty"【转】
    chrome浏览器新建标签打开页面【学习笔记】
    jz2440-uboot-201204版本移植【学习笔记】【原创】
    Ubuntu 14.04 下安装 TFTP 艰辛之路【转】
    更改UBoot实现通过loady命令下载代码【转】
  • 原文地址:https://www.cnblogs.com/chucklu/p/13266711.html
Copyright © 2011-2022 走看看