How to disable NLog from sending emails when running MVC3 app on localhost

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to disable NLog from sending emails when running MVC3 app on localhost

MarcusAberg


Does anyone know how to disable the NLog application from sending out emails when running tests on the MVC3 application on localhost? I would like NLog to only send out emails when the application gets en error when deployed to the webserver. What would I have to write in order to accomplish that?

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to disable NLog from sending emails when running MVC3 app on localhost

Jason LaFlair
Administrator
A lot depends on how you are configuring NLog.

So, without knowing that you could try a compiler directive within the Application_Start in your Global.asax.cs

protected void Application_Start()
{
#if DEBUG
            NLog.LogManager.DisableLogging();
#endif

....... other mvc code here ......

}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to disable NLog from sending emails when running MVC3 app on localhost

MarcusAberg
Hi Jason!

Your answer wasn't really the answer I was looking for, but it got me in the right direction!

I read the "ServiceAdress" value from web.config and in Application_Error-method where I log the error, and just added to the if -case "if the value from the ServiceAdress != "localhost" then do Log (after using Substring on it).

Thank you for your help :)
Loading...