asp.net - MVC4: How to pass custom error log + exception to Elmah? -


i pass custom error message along raised exception elmah source. example have class

public class activity {    public string id { get; set; }          public committee committee { get; set; }            public contact contact { get; set; }     [range(1950, 2050, errormessage = "{0} must between {1} , {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; } } 

when exception raised, don't have class prop values in exception. want pass these values , exception elmah.

now doing

 catch (exception exception)             {                  elmah.errorsignal.fromcurrentcontext().raise(exception);                 return view("error");             } 

how can do?

override tostring() method in class , raise exception so:

catch (exception exception) {   var newexception = new exception(yourclass.tostring(), exception);   elmah.errorsignal.fromcurrentcontext().raise(newexception); } 

in activity class:

public override string tostring() {    //return concatenate property names , values here ....  } 

Comments