zoukankan      html  css  js  c++  java
  • NLog——ElasticSearch——Kibana

    Nlog、elasticsearch、Kibana以及logstash在项目中的应用(一)

    Nlog、elasticsearch、Kibana以及logstash在项目中的应用(二)

    ASP.NET Core logging with NLog and Elasticsearch

     一、

    .Net Core引用的nuget包;可以配置Elasticsearch的url地址

     二、

    NLog.config示例:

    <?xml version="1.0" encoding="utf-8" ?>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
          autoReload="true"
         >
      <extensions>
        <add assembly="NLog.Targets.ElasticSearch"/>
      </extensions>
    
      <!-- optional, add some variabeles
      https://github.com/nlog/NLog/wiki/Configuration-file#variables
      -->
      <variable name="myvar" value="myvalue"/>
    
      <targets async="true">
        <target xsi:type="File" name="File" archiveAboveSize="20000000" fileName="${environment:variable=NLOGDIR}/*****.log" layout="[${date:format=yyyy-MM-dd HH:mm:ss}][${level}] ${logger} ${message} ${exception:format=toString} ${aspnet-request:cookie=String:serverVariable=String:queryString=String:item=String:form=String:header=String}" 
       archiveNumbering="Rolling"  encoding="UTF-8" enableFileDelete="true"  maxArchiveFiles="5" />
        <target name="ElasticSearch" xsi:type="ElasticSearch" ConnectionStringName="ElasticSearchServerAddress"  index="*****-${date:format=yyyy.MM.dd}" documentType="logevent" includeAllProperties="true"
             layout="[${date:format=yyyy-MM-dd HH:mm:ss}][${level}] ${logger} ${message} ${exception:format=toString}">
          <field name="MachineName" layout="${machinename}" />
          <!--<field name="AllEventProperties" layout="${all-event-properties:format=[key]=[value]:separator=;:includeCallerInformation=true}" />-->
          <field name="Time" layout="${longdate}" />
          <field name="level" layout="${level:uppercase=true}" />
          <field name="logger" layout=" ${logger}" />
          <field name="message" layout=" ${message}" />
          <field name="exception" layout=" ${exception:format=toString}" />
          <field name="processid" layout=" ${processid}" />
          <field name="threadname" layout=" ${threadname}" />
          <field name="stacktrace" layout=" ${stacktrace}" />
          <field name="Properties" layout="${machinename} ${longdate} ${level:uppercase=true} ${logger} ${message} ${exception}|${processid}|${stacktrace}|${threadname}" />
        </target>
      </targets>
    
      <rules>
        <!-- add your logging rules here -->
        <!--<logger name="*"     minlevel="Trace" writeTo="EventLog" />-->
        <logger name="*"     minlevel="Trace" writeTo="File" />
        <logger name="*"    minlevel="Trace" writeTo="ElasticSearch" />
      </rules>
    
    </nlog>
    

    三、

    设值环境变量ElasticSearchServerAddress:NLog.config中指定的

    或者,在appsettings.json中添加ElasticSearchServerAddress的配置节点

      

  • 相关阅读:
    算法练习题
    牛XX面试题
    web前端面试题
    在js中什么情况下会返回undefined
    yarn
    Web 开发技巧
    dll 文件创建与使用
    【转】 VS2008在64位Windows平台上编译ArcEngine导致HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)错误的解决办法
    Googlemap获取经纬度For APIV3
    javascript局部变量/全局变量
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/8352248.html
Copyright © 2011-2022 走看看