开发者

Nlog Logging an Object

Let's say I want to log an object Mycustomer using Nlog.

I want to have something like this:

logger.Trace(mycustomer)

Now in the configuration how can I specify which property I want to print? something like:

      <target name="output" xsi:type开发者_开发知识库="Debugger" layout="${Name}" />


i got it

instead of logger.log(customer);

i use this to add properties of customer:

        NLog.LogEventInfo info = new LogEventInfo(LogLevel.Info,"Name",cus.Name);
        info.Properties.Add("Name",cus.Name);
        log.Log(info);

and in config i use this to print it:

  <target name="output" xsi:type="Debugger" layout="${event-context:item=Name}"  />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜