I want to add my own session variable to elmah error log table and display it. I already have modified the source code and added the new fields to Error.cs and other fields but I don’t know but when I assign an HttpContext.Current.Session[“MyVar”].tostring() value to my field in the constructor it stops logging exceptions and does not log any exception.
I just need to get the value of the session variable is there other way for this ? I read a post which he added fields for the email but it does not say where exactly should I get the session value. I also read that Session and Cookies ar e logged by default by Elmah but I dont know how to access them..Thanks to everyone for their help.
Without seeing your source code I can only make assumptions, but I think Elmah stops logging because you get an exception. This might happen because the
Sessionproperty is null. The session is only available after thePostAcquireRequestStateevent and therefore you cannot count on this property to be always available.I tried this myself and wrote a method like this:
I call this method in the constructor of the Error class like this:
(just after server variables and the other context stuff gets copied. You will probably need to change the
IClonableimplementation to copy the_sessionfield, too.)In my tests this works as expected. I only checked in the
SqlErrorLogclass, but this will be the same for all the other ErrorLog classes: The error object contained all my session variables and I could store them in the database in whatever way I wanted.