Tutorial :ELMAH - pass variable, and other text?



Question:

I've just started playing with ELMAH.

was wondering, is there a way to pass info, eg a variable value, or some other text when an exception is thrown?.

Currently Im using this: ErrorSignal.FromCurrentContext().Raise(e);


Solution:1

The variable depends on the context of the exception? Or is it global (Session value?) If it's depending on context, you can just try catch and redirect an exception with a custom message manually to Elmah.

edit: snippet ... .Raise(new Exception("Your custom message with variable value"));


Solution:2

You can include the exception object with your custom message like this:

ErrorSignal.FromCurrentContext().Raise(new Elmah.ApplicationException(Message,ex));  

As seen on http://blog.omniaconnect.net/2009/07/30/using-a-static-class-for-logging-exceptions-using-elmah/


Solution:3

One way to do this is to extend elmah a bit so that it copies the session. The basic implementation is outlined here. This feature does not seem to be implemented in 1.2 (still beta), but I could be wrong about that.


Solution:4

I throw a new exception containing the data, using the innerexception parameter to contain the original exception.


Solution:5

It does suck that you are basically stuck with passing strings into elmah, but that's what exceptions are based on when you get to the meat of it (at least how most programmers deal with them).

What I do is just create custom messages that fake an object, kinda like:

Error occurred in Class.MethodName on Client Installation etc and then inject the existing exception.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »