Custom Formatting
See original GitHub issueI am using Serilog HTTP (5.0.1 version) sink for logging to Logstash in my .Net Core Project. In startup.cs I have following code to enable serilog.
Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Http("http://mylogstashhost.com:5000").Enrich.WithProperty("user", "xxx").Enrich.WithProperty("serviceName", "yyy") .MinimumLevel.Warning() .CreateLogger();
My events are being send as the following format.
{"events":[{"Timestamp":"2018-10-19T18:16:27.6561159+01:00","Level":"Warning","MessageTemplate":"abc","RenderedMessage":"abc","user":"xxx","serviceName":"yyy","Properties":{"ActionId":"b313b8ed-0baf-4d75-a6e2-f0dbcb941f67","ActionName":"MyProject.Controllers.HomeController.Index","RequestId":"0HLHLQMV1EBCJ:00000003","RequestPath":"/"}}]}
But seems receiving Logstash endpoint does not accept such format and I can not see my logs on Kibana. But when I send as following format all is ok.
{"Timestamp":"2018-10-19T18:16:27.6561159+01:00","Level":"Warning","MessageTemplate":"abc","RenderedMessage":"abc","user":"xxx","serviceName":"yyy","Properties":{"ActionId":"b313b8ed-0baf-4d75-a6e2-f0dbcb941f67","ActionName":"MyProject.Controllers.HomeController.Index" ,"RequestId":"0HLHLQMV1EBCJ:00000003","RequestPath":"/"}}
So Logstash doesnt like the event to be in Events{} and also it wants “user” and “ServiceName” tags out of “Properties”. I read posts about custom formatting, tried to use CompactJsonFormatter, JsonFormatter but none of them gave me what i wanted. Is there a way to achieve this ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Very good, let me know if you encounter any other problems.
Thanks for your help. I could achieve the format i need, by modifying ArrayBatchFormatter a little:
`public class MyFormat : BatchFormatter { public MyFormat(long? eventBodyLimitBytes = 256 * 1024): base(eventBodyLimitBytes) {