我正在使用ASPNet MVC4和在Global.asax上配置的HandleErrorAttribute过滤器
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
Run Code Online (Sandbox Code Playgroud)
在我的web.config上,我已将customError模式配置为RemoteOnly:
<customErrors mode="RemoteOnly" />
Run Code Online (Sandbox Code Playgroud)
因此,当在任何View上引发异常时,用户被重定向到〜/ Shared/Error.cshtml,这没关系.
现在,我可以捕获日志的这个异常:
〜/ Shared/Error.cshtml代码:
@{
log4net.LogManager
.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
.Fatal("Not captured exception", ex);
}
Run Code Online (Sandbox Code Playgroud)
实际上这段代码工作正常(没有EX参数),但我需要改进我的日志,包括异常细节.
我如何在此页面上获取异常详细信息?
我正在使用Microsoft.QualityTools.Testing.Fakes来模拟一些单元测试.
但此程序集仅适用于使用VisualStudio Ultimate的用户.
具有其他版本(专业版)的用户无法构建和运行此测试项目,并且在其环境中出现错误.
所以我创建了一个编译器指令来处理这个问题:
#define Ultimate
#if Ultimate
using Microsoft.QualityTools.Testing.Fakes;
#endif
Run Code Online (Sandbox Code Playgroud)
我的测试方法是:
#if Ultimate
using (ShimsContext.Create())
{
... My code
}
#else
Assert.Inconclusive("This test needs VS Ultimate to run");
#endif
Run Code Online (Sandbox Code Playgroud)
这很有效,但用户仍需要注释/取消注释定义行.
那么,有没有办法将我的VS版传递给编译器?或者还有另一种方法吗?
c# unit-testing compiler-options visual-studio vs-unit-testing-framework