Reputation: 1
I am using NLog 4.4.9 to log the info/error/exception. I am using following config settings and code to log exception. It logs other information but does not log exception. What am I doing anything wrong?
<target name="RollingFile"
layout="${log4jxmlevent:includeAllProperties=true}"
type="File"
fileName="${LogDir}/webapi.log"
encoding="utf-8"
maxArchiveFiles="10"
archiveNumbering="Sequence"
archiveAboveSize="1048576"
archiveFileName="${LogDir}/{#######}.a">
Logger = LogManager.GetLogger("ABC.Error");
LogEventInfo logEventInfo = new LogEventInfo();
logEventInfo.Level = LogLevel.Info;
logEventInfo.Message = "This is test message";
logEventInfo.Properties["UserId"] = "DAVESAURABH";
logEventInfo.Exception = e;
Logger.Log(LogLevel.Info, logEventInfo);
Upvotes: 0
Views: 1106
Reputation: 6363
Sometimes the default layout does NOT include the error e.g.
${longdate}|${level:uppercase=true}|${logger}|${message}
You'll have to add it manually e.g.
${longdate}|${level:uppercase=true}|${logger}|${message}|${error}
Hope this is what you're looking for.
Upvotes: 1