The event context layout renderer gets its parameters from the LogEventInfo parameter, for example:
http://nlog-project.org/wiki/Event-context_layout_renderer
However the LogEventInfo parameter is available in only 2 of the Log method signatures:
public void Log(Type wrapperType, LogEventInfo logEvent)
public void Log(LogEventInfo logEvent)
How can I pass the LogEventInfo if I want to use other Log methods, for example:
public void Log<T>(LogLevel level, IFormatProvider formatProvider, T value)
public void Log(LogLevel level, LogMessageGenerator messageFunc)
public void LogException(LogLevel level, [Localizable(false)] string message, Exception ecxception)
Assuming this is not possible in NLog 2.0, what workarounds are available?
The latter Log methods you have listed are really just convenience methods over the first two. In other words, they just construct
LogEventInfos themselves. When you use the first two methods, you’re circumventing the convenience for the sake of greater customization.To recreate the functionality of the convenience methods, you have to play around a bit with
LogEventInfo.The plus side of doing it with a
LogEventInfo, again, is that you can then go on to customize the logging event even further before callingLog().