开发者

Nlog Logging an Object

开发者 https://www.devze.com 2023-02-11 08:06 出处:网络
Let\'s say I want to log an object Mycustomer using Nlog. I want to have something like this: logger.Trace(mycustomer)

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

精彩评论

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