Log to xml file and sql database

271 views
Skip to first unread message

clayton...@gmail.com

unread,
May 12, 2009, 3:35:59 AM5/12/09
to ELMAH
Hello

Is it possible for elmah to log an exception to a xml file and to a
sql server database?
I have tried to include both errorLog tags in the web.config only to
have the error message saying "Sections must only appear once per
config file".

Thanks

James_2JS

unread,
May 12, 2009, 4:34:59 AM5/12/09
to ELMAH
Hi there

> Is it possible for elmah to log an exception to a xml file and to a
> sql server database?

At the moment, this is not possible. You can only log to one ErrorLog
at a time.

Cheers,

James

clayton...@gmail.com

unread,
May 12, 2009, 4:56:56 AM5/12/09
to ELMAH
Hello James

Thanks for the response.

I have another question:
I would like to catch an exception in my code and throw a
customException of my own without having elmah log the exception at
that line of code.

The reason i want elmah to delay the logging of the exception is
because i want it to bubble up to the Global.asax and then only do i
want it to log my customException using the
'ErrorSignal.FromCurrentContext().Raise()' method . This provides me
with a central location for logging all errors.

Cheers

James_2JS

unread,
May 12, 2009, 5:09:38 AM5/12/09
to ELMAH
Hi again,

> I have another question:
> I would like to catch an exception in my code and throw a
> customException of my own without having elmah log the exception at
> that line of code.

OK... so you're basically going to wrap an exception in a
customException then.

> The reason i want elmah to delay the logging of the exception is
> because i want it to bubble up to the Global.asax and then only do i
> want it to log my customException using the
> 'ErrorSignal.FromCurrentContext().Raise()' method . This provides me
> with a central location for logging all errors.

I'm not sure quite why you want to do this though. By wrapping the
exception, you then lose the ability to filter errors based on type.
Also, when you view the errors via elmah.axd, you will have to drill
into each error to see its nested type, thus making it less useful.

I also don't see why you would want to intercept the error in
Global.asax and then "manually" get ELMAH to log it. Why not leave
ELMAH to do its thing, and keep your own code more simple??!

Could you explain the reason why you are trying to do this in a bit
more depth?

Cheers,

James

clayton...@gmail.com

unread,
May 12, 2009, 7:01:44 AM5/12/09
to ELMAH
Hi

Yes that is correct, my strategy is to be able to catch the exception,
add it to my own customException along with other relevant data that
will enable me to group and identify the exception thrown so that i
can easily determine its cause and possible troubleshooting
recommendations.

Its mainly to make it easier and more explanative for the developer
who has to go back and debug it.
This question stems from the idea of being able to provide extra
information about the exception being thrown which results in me
having to ask you another question: Is it possible to add extra fields
to the Errror object & elmar_error table so that more information can
be logged?

Hope this is enough information.

Atif Aziz

unread,
May 12, 2009, 8:36:41 AM5/12/09
to el...@googlegroups.com
Is it possible for elmah to log an exception to a xml file and to a
sql server database?


This cannot be done out of the box but anything is possible if you're willing to write a bit of code. ;) There is an open model (subclass ErrorLog) so that you can plug-in your own particular requirements. You can perfectly write an error log implementation that delegates to two other. Bear in mind that logging to two other targets is always the easier part of the equation. The tougher bit is displaying errors from two sources. Which of the two do you display? Do you display a unique set of the two? Do you display errors from both and in which order?

Atif Aziz

unread,
May 12, 2009, 8:56:23 AM5/12/09
to el...@googlegroups.com
This question stems from the idea of being able to provide extra
information about the exception being thrown which results in me
having to ask you another question: Is it possible to add extra fields
to the Errror object & elmar_error table so that more information can
be logged?

This is not possible out of the box either. This is something we'd be looking into moving forward as its been asked for before:
http://code.google.com/p/elmah/issues/detail?id=53

clayton...@gmail.com

unread,
May 12, 2009, 9:41:50 AM5/12/09
to ELMAH
Hi,

Thanks for pointing me in the right direction.
I still need some clarity on whether i can delay the writing of the
exception being thrown until its bubbled up to the Global.asax
Application_Error method?

On May 12, 2:56 pm, Atif Aziz <aziza...@gmail.com> wrote:
> > This question stems from the idea of being able to provide extra
> > information about the exception being thrown which results in me
> > having to ask you another question: Is it possible to add extra fields
> > to the Errror object & elmar_error table so that more information can
> > be logged?
>
> This is not possible out of the box either. This is something we'd be
> looking into moving forward as its been asked for before:http://code.google.com/p/elmah/issues/detail?id=53
>
> On Tue, May 12, 2009 at 1:01 PM, clayton.aren...@gmail.com <

Atif Aziz

unread,
May 12, 2009, 10:52:30 AM5/12/09
to el...@googlegroups.com
I still need some clarity on whether i can delay the writing of the
exception being thrown until its bubbled up to the Global.asax
Application_Error method?

From memory, I believe that Application_Error in Global.asax is called after the same event in any other HTTP module, including those of ELMAH. In effect, you can't delay things because by the time your Application_Error is called, ErrorLogModule form ELMAH will have logged the error. What you can do is play a lot hacks to get what you want but I don't know if it's worth the trouble. From the sound of it, it looks like you don't want ELMAH to log it automatically. In that case, I wouldn't register ErrorLogModule and simply log the error in Application_Error using ErrorLog.

clayton...@gmail.com

unread,
May 18, 2009, 9:16:38 AM5/18/09
to ELMAH
Hi Atif

It works great, I have made the change by not registering
ErrorLogModule in the web.config and now it only logs in the
global.asax when calling the ErrorLog.Default.Log method.

Thanks.

On May 12, 4:52 pm, Atif Aziz <aziza...@gmail.com> wrote:
> > I still need some clarity on whether i can delay the writing of the
> > exception being thrown until its bubbled up to the Global.asax
> > Application_Error method?
>
> From memory, I believe that Application_Error in Global.asax is called after
> the same event in any other HTTP module, including those of ELMAH. In
> effect, you can't delay things because by the time your Application_Error is
> called, ErrorLogModule form ELMAH will have logged the error. What you can
> do is play a lot hacks to get what you want but I don't know if it's worth
> the trouble. From the sound of it, it looks like you don't want ELMAH to log
> it automatically. In that case, I wouldn't register ErrorLogModule and
> simply log the error in Application_Error using ErrorLog.
>
> On Tue, May 12, 2009 at 3:41 PM, clayton.aren...@gmail.com <
Reply all
Reply to author
Forward
0 new messages