EL+Serilog日誌
簡介
Elasticsearch 是一個實時的分散式搜索分析引擎,它能讓你以前所未有的速度和規模,去探索你的數據。 它被用作全文檢索、結構化搜索、分析以及這三個功能的組合:
安裝
Elasticsearch安裝
- 你可以從 elastic 的官網 //www.elastic.co/cn/downloads/elasticsearch獲取最新版本的 Elasticsearch。
- windows系統上:bin\elasticsearch.bat
- 接著我們運行:curl ‘//localhost:9200/?pretty‘
- 我們會得到
{
"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安裝
- Sense 是一個 Kibana 應用 它提供互動式的控制台,通過你的瀏覽器直接向 Elasticsearch 提交請求。
- 1:在 Kibana 目錄下運行下面的命令,下載並安裝 Sense app
- 2:NOTE:你可以直接從這裡 //download.elastic.co/elastic/sense/sense-latest.tar.gz 下載 Sense
- 接著啟動kibana
- 在你的瀏覽器中打開 Sense: //localhost:5601/app/sense 。
Kibana安裝
- 具體地址官網下載即可
- kibanan.yml修改
server.port: 5601
server.host: "localhost"
elasticsearch.hosts: ["//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": "//localhost:9200;//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裡面都有說明。訪問官方文檔也可以