简体   繁体   中英

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}"  />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM