Asp.net MVC4:如何传递自定义错误日志+;艾玛的例外?
我想将一些自定义错误消息和引发的异常一起传递给elmah source。比如我有课Asp.net MVC4:如何传递自定义错误日志+;艾玛的例外?,asp.net,asp.net-mvc,asp.net-mvc-4,elmah,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Elmah,我想将一些自定义错误消息和引发的异常一起传递给elmah source。比如我有课 public class Activity { public string Id { get; set; } public Committee Committee { get; set; } public Contact Contact { get; set; } [Range(1950, 2050, ErrorMessage = "{0} must be b
public class Activity
{
public string Id { get; set; }
public Committee Committee { get; set; }
public Contact Contact { get; set; }
[Range(1950, 2050, ErrorMessage = "{0} must be between {1} and {2}.")]
[DisplayName("Activity End Date")]
public int? EndDate { get; set; }
[DisplayName("Source")]
public string Source { get; set; }
[DisplayName("Activity Role")]
public string Role { get; set; }
[DisplayName("Comments")]
public string Comments { get; set; }
}
当引发异常时,我的异常中没有此类属性值。所以我想把这些值和异常传递给elmah
现在我在做什么
catch (Exception exception)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
return View("Error");
}
如何做?重写类中的
ToString()
方法并引发异常,如下所示:
catch (Exception exception)
{
var newException = new Exception(yourClass.ToString(), exception);
Elmah.ErrorSignal.FromCurrentContext().Raise(newException);
}
在您的活动中
课程:
public override string ToString()
{
//return concatenate the property names and values here ....
}