I have a format that I need to follow for logging. I am writing out to the FileSink with a
Serilog.Log.Logger = new LoggerConfiguration()
.WriteTo.Sink(new FileSink(ConfigurationManager.AppSettings["serilogPath"],new JsonFormatter(), null))
.CreateLogger();
This generates a per-line JSON object looking like (I formatted it, it is actually one line in the log file):
{
"Timestamp": "2016-05-29T02:49:33.2153863+08:00",
"Level": "Error",
"MessageTemplate": "my template",
"Properties": {
<MyPropertiesHere>
}
}
I have asked from another question that I need to specify my own json formater to remove the timestamp/level/messagetemplate, which I can do, but ultimately, what I need is something like a combination of the output of a File and a FileSink with JSON (I formatted this as well. It should be all in one line):
2016-06-03 11:19:33.343 +08:00 [Information] {
"MyCustomKeyName": {
"key1": "val1",
"key2": "val2"
}
}
With my current configuration, the JSON object is showing the correct serialized form of the object, but I need the timestamp, [Information] field (could be error/warning as well), and the ability to rename the "Properties" key to "MyCustomKeyName".
The timestamp and the [Information] information is what I get by default when using a WriteTo.File, but my goal is to obtain that from using a FileSink with json formatter. With the FileSink, I am getting one whole JSON object with the fields encapsulated inside as key/val pairs. I want to have the timestamp and level information preceding the JSON object. The goal is to have logstash parse it.
Thank you.