Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net MVC4:如何传递自定义错误日志+;艾玛的例外?_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Elmah - Fatal编程技术网

Asp.net MVC4:如何传递自定义错误日志+;艾玛的例外?

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

我想将一些自定义错误消息和引发的异常一起传递给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 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 .... 
}