Override default serializer for SerializedLayout in log4net.Ext.Json -
i'm trying log4net.ext.json serialize json. want output this:
{ "data": { "objectfield1": "foo", "objectfield2": "bar", "time": "2015-05-11t12:35:00.05215z" } }
where objectfield1
, objectfield2
come message object on loggingevent
, time
comes log4net pattern this:
%utcdate{yyyy-hh-mm-dd}t%utcdate{hh:mm:ss.fffff}z
is there way add properties message object via configuration? tried following no avail:
<layout type="log4net.layout.serializedlayout, log4net.ext.json"> <member value="data:messageobject" /> <arrangement value="data:messageobject=time|%utcdate{yyyy-hh-mm-dd}t%utcdate{hh:mm:ss.fffff}z" /> <renderer type="log4net.objectrenderer.jsonobjectrenderer, log4net.ext.json"> <!-- please ignore custom serializer factory setting below --> <factory type="log4net.util.serializer.jsondotnetserializer, log4net.ext.json.serializers" /> </renderer> </layout>
you can achieve either logging such structured object:
log.info(new { data = new { objectfield1 = "foo", objectfield2 = "bar" } });
and using messageobject member only.
or, see if multiplearrangement
somewhere:
<member value="data=objectfield1\;objectfield2\;time" />
it can used explicitly:
<layout type="log4net.layout.serializedlayout, log4net.ext.json"> <arrangement value="data" type="log4net.layout.arrangements.multiplearrangement, log4net.ext.json"> <arrangement value="objectfield1" type="..." /> <arrangement value="objectfield2" type="..." /> </arrangement> </layout>
Comments
Post a Comment