Make sure you set your application name in web.config
<errorLog type="Elmah.SqlErrorLog, Elmah"
connectionStringName="nibWeb"
applicationName="Nib.Services" />
and then
ErrorLog.GetDefault(null).Log(new Error(error));
will work
I wasn't using <errorLog>
as in Brendan Carey's answer because I was only in-memory logging. Nevertheless, his command worked great in my case without naming the application:
Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(new Exception("The application has done something.")));
I DID have to recompile Elmah with .NET 4.0, because of an error about needing System.Web.Abstractions 3.5.0.0. My compiled-for-.NET 4.0 fork is here if anyone wants it (also strong naming):
http://code.google.com/r/scottstafford-elmah/
For my application, I saved this.Context.ApplicationInstance
in Application_Start
so that I can call Elmah.ErrorSignal.Get
with the saved instance. With the ErrorSignal
, I could then Raise
. This goes through all the email filters.
Below is the code. I use FluentScheduler to
public class Global : HttpApplication {
void Application_Start(object sender, EventArgs e) {
var application = Context.ApplicationInstance;
FluentScheduler.TaskManager.UnobservedTaskException +=
(FluentScheduler.Model.TaskExceptionInformation i, UnhandledExceptionEventArgs a) =>
Elmah.ErrorSignal.Get(application).Raise(i.Task.Exception);
}
}
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