0
votes

For a project I'm using Castle Windsor DI (new for me). The Castle.Core.Logging namespace with its interface Logger has these methods (also with Debug, Error etc):

  • void Fatal(string message, Exception exception);
  • void Fatal(string message);

However, when I'm using the methods with the exception parameter, it only logs the message, not the exception. I can't seem to figure out why it only logs the message, maybe I missed a setting? Currently NLog is used for logging. The logger is injected in a base class like this:

public ILogger Log { get; set; } = NullLogger.Instance;

This setup is from NLog and Castle Logging Facility for Logging

1
Please share your NLog config. Are us using ${exception}?Julian

1 Answers

2
votes

You can customize the layout and the content of the messages Nlog will give you by setting this inside the Nlog config file. For this you could write for example:

<targets>
    <!-- write logs to file -->
    <target xsi:type="File" name="logfile" fileName="c:\temp\console-example.log"
            layout="${longdate}|${level}|${message} |${all-event-properties}${exception:format=tostring}" />
    <target xsi:type="Console" name="logconsole"
            layout="${longdate}|${level}|${message} |${all-event-properties}${exception:format=tostring}" />
  </targets>

https://github.com/NLog/NLog/wiki/Getting-started-with-.NET-Core-2---Console-application