Nlog Object Registration

Let's say I want to register a Mycustomer object 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? sort of:

      <target name="output" xsi:type="Debugger" layout="${Name}" />
+3
source share
1 answer

I recieved it

instead logger.log(customer);

I use this to add client properties:

        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:

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

Source: https://habr.com/ru/post/1793366/


All Articles