开发者

ELMAH - pass variable, and other text?

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);


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/


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"));


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜