When using ELMAH (which is brilliant) is it possible to view extra information that you have added to an exception.
E.g.
Exception ex = new Exception("New exception to use ErrorSignal functionality");
ex.Data.Add("ExtraInfo", "Here is some extra information i would like to be displayed.");
ErrorSignal.FromCurrentContext().Raise(ex);
When I view the exception from elmah.axd it doesn’t seem to show the “ExtraInfo” key and value information, just the exception string.
My solution was to add the information to the Server Variables collection like so.
var context = HttpContext.Current;
context.Request.ServerVariables["ERROR_CALLING_WEBSERVICE_URI"] = uri;
Elmah.ErrorLog.GetDefault(context).Log(new Error(e, context))
Yes, I Think this is a hack.
For small amounts of additional data consider encapsulating the error as suggested by @Roma
However this method is especially useful where you have too much information to put into an 'encapsulated error message'
Elmah uses ToString() method to get exception details. Just override your custom exception ToString() method and this way it will work:
My exception class:
public class MyCustomException : Exception
{
public string CustomProperty { get; set; }
public MyCustomException(string message, string customProperty): base(message)
{
this.CustomProperty = customProperty;
}
public override string ToString()
{
var result = base.ToString();
var propertyData = String.Format("CustomProperty: {0}", this.CustomProperty);
return result.Insert(
result.IndexOf(Environment.NewLine),
Environment.NewLine + propertyData
);
}
}
The simple way to go around, is to encapsulate the error. The outer error will contain you custom message.
string msg = "my custom error message";
ErrorSignal.FromCurrentContext().Raise(
new Elmah.ApplicationException(msg,ex));
No, it is not possible to view the extra information with the current 1.x releases.
Ok, so I have been waiting for this to be included for too long now and decided to make a own fork of it and include the feature myself.
You can find it here: https://github.com/boena/elmah-with-custom-data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With