How to log json inside json at correct format

  • Thread starter Thread starter AishwaryaKasi
  • Start date Start date
A

AishwaryaKasi

Guest
In log4net.config file i am having the following appender.



I was using JsonLogging appender for logging using log4net. If i try to log json string then json is logged like string not as an json. How can i handle this scenario ? The message inside message attribute contains json as string. I want to log that as json.

<appender name="JsonLogging" type="log4net.Appender.RollingFileAppender">
<file value="E:\\april.log" />
<appendToFile value="true" />
<staticLogFileName value="true" />
<rollingStyle value="Date" />
<datePattern value="'_'yyyy_MM_dd"/>
<PreserveLogFileNameExtension value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.SerializedLayout, log4net.Ext.Json">
<decorator type="log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json" />
<default />
<remove value="message" />
<remove value="ndc"/>
<member value="message:messageobject"/>
</layout>
</appender>



{
"date":"2019-04-02T13:17:02.6719961+05:30",
"level":"INFO",
"appname":"Test.exe",
"logger":"Test.Program",
"thread":"1",
"message":{
"message":"{\"Consumer\":{\"os\":\"Microsoft Windows\",\"Test\":\"test\",\"name\":null,\"machine\":\"testmachine\"}}",
"customer":"Customername"
}
}



private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
log.Info(message(jsonstring));


public static object message(object msg)
{
return new { message = msg, customer = CustomerName };
}

Continue reading...
 
Back
Top