I would like to write a helper function which build the exception message to write to a log. The code look like:
if(IsWebApp)
{
&
I use the DomainManager type of Current AppDomain. MSDN documentation of AppDomainManager
public static class AspContext
{
public static bool IsAspNet()
{
var appDomainManager = AppDomain.CurrentDomain.DomainManager;
return appDomainManager != null && appDomainManager.GetType().Name.Contains("AspNetAppDomainManager");
}
}
You can also check this other answer on SO