![](/img/trans.png)
[英]Add the custom analyzer universally to all the fields in Nest Elastic search 6.2
[英]Serilog configuration for elastic search with custom fields
我正在配置ABP框架,並希望使用Serilog進行日志記錄。 我在Startup.cs中具有以下配置。
var logger = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("https://xxxxxxxxxx.com"))
{
AutoRegisterTemplate = true,
TemplateName = "app-log",
IndexFormat = "app-log-{0:yyyy.MM.dd}",
CustomFormatter = new ElasticsearchJsonFormatter()
})
.WriteTo.File("Serilogs.txt")
.MinimumLevel.Information()
.CreateLogger();
Log.Logger = logger;
option.AddSerilog(logger);
通過這種配置,我將獲得以下格式的日志:
{
"_index": "app-log-2017.12.18",
"_type": "logevent",
"_id": "******",
"_version": 1,
"_score": null,
"_source": {
"@timestamp": "2017-12-18T15:34:54.3417552+05:30",
"level": "Information",
"messageTemplate": "{HostingRequestStartingLog:l}",
"fields": {
"Protocol": "HTTP/1.1",
"Method": "GET",
"ContentType": null,
"ContentLength": null,
"Scheme": "http",
"Host": "localhost:21021",
"PathBase": "",
"Path": "/swagger/",
"QueryString": "",
"HostingRequestStartingLog": "Request starting HTTP/1.1 GET http://localhost:21021/swagger/ ",
"EventId": {
"Id": 1
},
"SourceContext": "Microsoft.AspNetCore.Hosting.Internal.WebHost",
"RequestId": "****:****",
"RequestPath": "/swhaggfgggdefrf/"
},
"renderings": {
"HostingRequestStartingLog": [
{
"Format": "l",
"Rendering": "Request starting HTTP/1.1 GET http://localhost:21021/swagger/ "
}
]
}
},
"fields": {
"@timestamp": [
1513591494341
]
},
"sort": [
1513591494341
]
}
目前,我正在獲取@timestamp , level和message 。 通過使用Log.Logger.Information("Some Template")
,我們可以獲得字段形式的一些信息。
現在,在ABP框架中,每個事件都有一個日志。 誰能建議一種修改這些消息的方法? 例如,對於每個請求,它顯示請求開始HTTP / 1.1 GET http:// localhost :********** ,對於每個響應,它顯示請求完成在7.8262ms 301中 。 是否可以修改這些消息? 如果是,那怎么辦?
我可能不清楚某人。 如果需要進一步說明,請發表評論。 提前致謝。
您無法修改這些消息。 因為Asp.Net Core框架會寫那些日志。 您可以看到代碼的相關行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.