elasticsearch,.net-core,serilog,aspnetboilerplate,C#,elasticsearch,.net Core,Serilog,Aspnetboilerplate" /> elasticsearch,.net-core,serilog,aspnetboilerplate,C#,elasticsearch,.net Core,Serilog,Aspnetboilerplate" />

C# Serilog配置用于自定义字段的弹性搜索

C# Serilog配置用于自定义字段的弹性搜索,c#,elasticsearch,.net-core,serilog,aspnetboilerplate,C#,elasticsearch,.net Core,Serilog,Aspnetboilerplate,我正在配置ABP框架,希望使用Serilog进行日志记录。我在Startup.cs中有以下配置 var logger = new LoggerConfiguration() .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("https://xxxxxxxxxx.com")) { AutoRegisterTemplate = true, TemplateName = "app-l

我正在配置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和消息。 通过使用
Log.Logger.Information(“一些模板”)
,我们可以以字段的形式获得一些信息

现在,在ABP框架中,每个事件都有一个日志。有人能提出修改这些消息的方法吗? 例如,对于每个请求,它显示开始HTTP/1.1 GET:*********的请求,对于每个响应,它显示在7.8262ms 301中完成的请求。是否可以修改这些消息?如果是,那怎么办


我可能对某人不清楚。如果需要进一步澄清,请发表评论。提前感谢。

您不能修改这些消息。 因为Asp.Net核心框架会写入这些日志。 您可以看到代码的相关行


修改为什么?例如,我想修复MessageTemplate中的字段,如果该数据不可用于任何日志,则允许它们为空。比如:“字段:{“elapsedmillyseconds”:144.6361,“StatusCode”:200,“ContentType”:“application/javascript”,“HostingRequestFinishedLog”:“请求在144.6361ms 200 application/javascript中完成”,“EventId”:{“Id”:2},“SourceContext”:“Microsoft.AspNetCore.Hosting.Internal.WebHost”,“RequestId:“0HLAHOT40NGN8:00000006”,“RequestPath:”/swagger/ui/abc.js“},我看不出什么是空的。我的意思是,我想修复系统中每个日志的elapsedmillesons、StatusCode、ContentType和RequestPath的固定属性。任何消息都应该出现在一个字段中,例如EventLog。让它成为开始日志、结束日志或任何其他日志。根据@Alper的回答,这是由Asp.Net核心定义的,它是正确。但是,有可能覆盖它吗?你说的“想要修复”是什么意思。。。系统中每个日志的固定属性“?