MethodCallTarget target = new MethodCallTarget("MyTarget",
(logEvent, parms) => WriteMessage(logEvent.Exception != null ? string.Concat(logEvent.FormattedMessage, " Exception: ", logEvent.Exception.ToString()) : logEvent.FormattedMessage);
如果您想利用NLog布局逻辑,可以这样做:
MethodCallTarget target = new MethodCallTarget("MyTarget",
(logEvent, parms) => WriteMessage(parms[0].ToString()));
target.Parameters.Add(new MethodCallParameter("AdvancedMessage", "${message}${onexception:EXCEPTION OCCURRED\:${exception:format=tostring}}"));