1

I'm using Common.Logging with the NLog adapter.

http://netcommon.sourceforge.net/docs/1.2.0/reference/html/logging.html

I'm calling this method:

void Error( object message, Exception exception );

The text of the "message" shows up in the Logs (a txt-file and in the EventLog), but the details about the exception do not. Not even the ex.Message.

Am I missing something?

How do I get the details about the Exception to show up. Do I have to just tack it on the "object message"? I guess having the overload'ed method with the exception, I thought there would be some auto-logging.

My NLog.config is fairly simple.

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets>
    <target name="logfile" xsi:type="File" fileName="MyFile.log.txt"/>
    <target name="console" xsi:type="Console" />
    <target xsi:type="EventLog"
             name="eventLog" 
             source="MySource"
       eventId="555"
             log="Application"
                     />
  </targets>
  <rules>
    <logger name="*" minLevel="Error" writeTo="eventLog" />
    <logger name="*" minLevel="Info" writeTo="console" />
    <logger name="*" minLevel="Info" writeTo="logfile"/>
  </rules>

</nlog>

EDIT:

Ok...based on the Sergey answer, I just roided up my setup:

layout="${longdate}|${level}|${callsite}|${logger}|${threadid}|${windows-identity:domain=false}__${message} ${exception:format=message,stacktrace:separator=*"
granadaCoder
  • 26,328
  • 10
  • 113
  • 146

1 Answers1

2

According to documentation, default layout is

${longdate}|${level:uppercase=true}|${logger}|${message}

You should specify ${exception} layout renderer to write exception info. E.g. set following layout for targets which should write exceptions:

${longdate}|${level:uppercase=true}|${logger}|${message}${newline}${exception}

If you want all targets to have same layout, you can move its definition to variable:

<variable name="verbose" 
          value="${longdate}|${level:uppercase=true}|${logger}|${message}${newline}${exception}" />
<targets>
   <target name="logfile" xsi:type="File" layout="${verbose}" fileName="log.txt" />
   <target name="console" xsi:type="Console" layout="${verbose}"/>
   <target name="eventLog" xsi:type="EventLog" layout="${verbose}"
           source="MySource" eventId="555" log="Application" />
</targets>
<rules>
   <logger name="*" minLevel="Error" writeTo="eventLog" />
   <logger name="*" minLevel="Info" writeTo="console,logfile" />
 </rules>
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
  • Ok. That was my disconnect. There is a default layout. Makes sense. I had wired up my database-logger with the more advanced layout, but not my event-log and text-file loggers. Thx. – granadaCoder May 30 '14 at 20:57
  • 1
    Superplus for the reusable "verbose" variable. – granadaCoder May 30 '14 at 20:59
  • @granadaCoder yep, cool feature. Also you can use logger which writes to several targets - as you can see, I've combined console and file targets – Sergey Berezovskiy May 30 '14 at 21:01