EL+Serilog日誌

簡介

Elasticsearch 是一個實時的分佈式搜索分析引擎,它能讓你以前所未有的速度和規模,去探索你的數據。 它被用作全文檢索、結構化搜索、分析以及這三個功能的組合:

安裝

Elasticsearch安裝

{
  "name" : "Tom Foster",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.1.0",
    "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",
    "build_timestamp" : "2015-11-18T22:40:03Z",
    "build_snapshot" : false,
    "lucene_version" : "5.3.1"
  },
  "tagline" : "You Know, for Search"
}

配置elasticsearch.yml 在config目錄下

 ---------------------------------- Cluster -----------------------------------
cluster.name: 你的引用
node.name: node-101
----------------------------------- Paths ------------------------------------
path.data: 數據路徑
path.logs: 日誌路徑
---------------------------------- Network -----------------------------------
這裏不貼出來了。配置成以下之後不知道爲什麼運行不起來
network.host: 0.0.0.0
http.port: 9200
--------------------------------- Discovery ----------------------------------
http.cors.enabled: true 
http.cors.allow-origin: "*" 
node.master: true 
node.data: true 

Sense安裝

Kibana安裝

  • 具體地址官網下載即可
  • kibanan.yml修改
server.port: 5601
server.host: "localhost"
elasticsearch.hosts: ["http://localhost:9200"]

logstash安裝

在config中新建logstash.conf

input {

    file {

        type => "nginx_access"

        path => "路徑"

    }

}

output {

    elasticsearch {
        hosts => ["127.0.0.1:9200"]
        index => "access-%{+YYYY.MM.dd}"
    }

    stdout {

        codec => json_lines
    }
}
  • 然後依次啓動就行了。這裏簡單贅述下

Serilog

簡介

  • Serilog 是一個用於.NET應用程序的日誌記錄開源庫,配置簡單,接口乾淨,並可運行在最新的.NET平臺上,與其他日誌庫不同, Serilog 是以功能強大的結構化事件數據爲基礎構建的, 支持將日誌輸出到控制檯、文件、數據庫和其它更多的方式,支持參數化日誌模板,非常靈活。
  • 首先,使用 NuGet 方式安裝 Serilog 核心庫
Install-Package Serilog
Install-Package Serilog.Sinks.Console

//配置
 public static void ConfigureSerilogConfig(this IServiceCollection services, IConfiguration configuration)
        {
            Serilog.Log.Logger = new LoggerConfiguration()
              .ReadFrom.Configuration(configuration)
              .CreateLogger();
      }

//json配置
  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Async", "Serilog.Sinks.File" ],
    "LevelSwitches": { "$controlSwitch": "Verbose" },
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Debug",
        "System": "Debug",
        "System.Net.Http.HttpClient": "Debug"
      }
    },
    "WriteTo:Async": {
      "Name": "Async",
      "Args": {
        "configure": [
          { "Name": "Console" }
        ]
      }
    },
    "WriteTo:Elasticsearch": {
      "Name": "Elasticsearch",
      "Args": {
        "nodeUris": "http://localhost:9200;http://remotehost:9200/",
        "indexFormat": "operation-broadcast-api-{0:yyyy.MM.dd}",
        "autoRegisterTemplate": true
      }
    },
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "Properties": {
      "Application": "operation"
    }
  },

具體得相關配置可以參照

  • serilog-settings-appsettings
  • serilog-settings-configuration
  • serilog-sinks-elasticsearch
    以上百度獲取github裏面都有說明。訪問官方文檔也可以
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章