Reputation: 1729
I'm using Elmah in my MVC4 application for handle exception. Then I installed NLog for debugging. When there is an exception
try
{
// There is exception occured here
}
catch (DataException ex)
{
logger.Log(LogLevel.Error, dex.Message);
ModelState.AddModelError("", "Unable to save changes");
}
Why NLog doesn't log the exception while elmah does? I want to log the exception using NLog and elmah, how to configure them?
Upvotes: 2
Views: 2757
Reputation: 466
I decided to post this as an answer as it was not clear in comments:
The NLog Documentation give a desciption of how to construct your web.config (or use a separate configuration file)
You need this block in your web.config
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog>
**** Nlog specific settings go here *****
</nlog>
</configuration>
Some example NLog settings:
<variable name="logDirectory" value="${basedir}/logs/${shortdate}"/>
<targets>
<target name="file1" xsi:type="File" fileName="${logDirectory}/file1.txt"/>
<target name="file2" xsi:type="File" fileName="${logDirectory}/file2.txt"/>
</targets>
Upvotes: 2