Signaling from a thread?

26 views
Skip to first unread message

Mobay

unread,
Feb 10, 2009, 10:11:36 AM2/10/09
to ELMAH
Hello

Just tried out this cool ELMAH project.

Everything works fine, but I am stuck trying to signal ELMAH from a
tread, that I have created with my ASP.NET 3.5 app.

The problem is that I have no HTTPContext and no
HTTPContext.ApplicationInstance inside that thread.

Im pretty sure i need those to log an error acording to the source
code:
http://code.google.com/p/elmah/source/browse/trunk/src/Elmah/ErrorSignal.cs

How would you suggest that I Signal ELMAH from a thread?

Thanks in advance!



Atif Aziz

unread,
Feb 11, 2009, 3:04:03 AM2/11/09
to el...@googlegroups.com
>>
The problem is that I have no HTTPContext and no
HTTPContext.ApplicationInstance inside that thread.
<<

Unfortunately, if you don't have an HttpContext object handy then ErrorSignal.Raise won't work. I can get into the "why" of it if you're interested, but let me ask you this...Are you interested in "unconditionally" logging the exception from your thread? If yes, the you can just do this:

ErrorLog.GetDefault(null).Log(new Error(ex));

Note that this will only log the error but not notify by e-mail if you also have the ErrorMailModule in place.

- Atif

Mobay

unread,
Feb 11, 2009, 6:55:05 AM2/11/09
to ELMAH
Hi Atif

Thank you for your answer.

Your suggestion to use this method:

ErrorLog.GetDefault(null).Log(new Error(ex));

- works fine since i just need the log as an RSS feed.

However when i use the above method, my application is named as an
empty field. Which is a problem since the rest of my app is showing
"/" in the SQL database.

So i cannot see the entrys logged, when viewing elmah.axd or the RSS
feed.

Is there anyway i can tell it to log in the same application name?

I tried to use something like:

ErrorLog.GetDefault(null).ApplicationName = "/";
ErrorLog.Default.ApplicationName = "/";

But i guess im not using it right?

Thanks!
> code:http://code.google.com/p/elmah/source/browse/trunk/src/Elmah/ErrorSig...

Atif Aziz

unread,
Feb 11, 2009, 7:36:35 AM2/11/09
to el...@googlegroups.com
> Is there anyway i can tell it to log in the same application name?

Yes, try:

var log = ErrorLog.GetDefault(null);
log.ApplicationName = "/";
log.Log(new Error(ex));

Mobay

unread,
Feb 12, 2009, 4:37:58 AM2/12/09
to ELMAH
Hello again

Thanks for the quick reply!

Your solution worked great!

One last question :-) Where can i find information about the
applicationName?

Because i would like to use my database for more than one app.

Right now every app is named "/" is there some way of changing this?

Thanks in advance!

Atif Aziz

unread,
Feb 12, 2009, 4:44:10 AM2/12/09
to el...@googlegroups.com
>>
Right now every app is named "/" is there some way of changing this?
<<

Yes you can set this in the configuration file. Below, you can see the applicationName attribute in action for SqlErrorLog:

<errorLog
type="Elmah.SqlErrorLog, Elmah"
applicationName="MyApp"
connectionString="Data Source=.;Initial Catalog=ELMAH;Trusted_Connection=True" />

HTH,

Mobay

unread,
Mar 23, 2009, 5:01:54 AM3/23/09
to ELMAH
Hello Atif

Forgot to thank you!

This was very helpfull information.
Reply all
Reply to author
Forward
0 new messages