I am configuring ABP framework and want to use Serilog for logging. I have the following configuration in 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);
With this configuration I am getting the log in following format:
{
"_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
]
}
Currently, I am getting the @timestamp, level and the message.
By using Log.Logger.Information("Some Template"), we can get some information in the form of fields.
Now, in the ABP framework, there is a log for each event. Can anyone suggest a way of modifying those messages? For example, for each request it shows Request starting HTTP/1.1 GET http://localhost:********** and for each response, it shows Request finished in 7.8262ms 301. Is it possible to modify these message? If yes then how?
I might not be clear for someone. Please comment if need any further clarifications. Thanks in advance.
