c# - Removing Default Properties in Serilog Output -
in serilog output in file, see default is
{ "timestamp": "2016-05-28t21:21:59.0932348+08:00", "level": "information", "messagetemplate": "processed {@number} records in {@time} ms", "properties": { "number": 500, "time": 120 } }
is there way remove timestamp, level, messagetemplate, , properties i"m left only
{ "number": 500, "time": 120 }
the log.logger assigned such
log.logger = new loggerconfiguration() .writeto.sink(new filesink(configurationmanager.appsettings["serilogpath"], new jsonformatter(), null)) .createlogger();
thanks
from looking @ source code, doesn't jsonformatter supports skipping default properties. create own itextformatter you're looking for. here's quick example (that should not used in production because doesn't escaping -- it's demo purposes):
public class soformatter : itextformatter { public void format(logevent logevent, textwriter output) { output.write("{"); foreach (var p in logevent.properties) { output.write("\"{0}\" : {1}, ", p.key, p.value); } output.write("}"); } }
Comments
Post a Comment