469,927 Members | 1,592 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Error Logging

I am trying to implement database error logging in my asp.net application.
When I inspect the exception variable, I see that there is a property called
'procedure' which I believe is the procedure or fucntion that caused the
error. How can I get at that variable to write it to my error log?

Thanks,
Denise
Nov 19 '05 #1
4 1153
We recently discussed this over at DevelopMentor's listserv:

http://discuss.develop.com/archives/...B&P=R3885&I=-3
http://discuss.develop.com/archives/...B&P=R3787&I=-3
-Brock
DevelopMentor
http://staff.develop.com/ballen
I am trying to implement database error logging in my asp.net
application. When I inspect the exception variable, I see that there
is a property called 'procedure' which I believe is the procedure or
fucntion that caused the error. How can I get at that variable to
write it to my error log?

Thanks,
Denise


Nov 19 '05 #2
Brock,

Thanks for your reply. But perhaps this is not the correct link. I don't
see any mention of referencing the 'procedure' property of an exception.

Denise
"Brock Allen" wrote:
We recently discussed this over at DevelopMentor's listserv:

http://discuss.develop.com/archives/...B&P=R3885&I=-3
http://discuss.develop.com/archives/...B&P=R3787&I=-3
-Brock
DevelopMentor
http://staff.develop.com/ballen
I am trying to implement database error logging in my asp.net
application. When I inspect the exception variable, I see that there
is a property called 'procedure' which I believe is the procedure or
fucntion that caused the error. How can I get at that variable to
write it to my error log?

Thanks,
Denise


Nov 19 '05 #3
AFAIK, the 'Procedure' property is available specifically for exceptions
that are of type SqlException, and it tells you the name of the SQL Server
stored procedure that threw an exception (perhaps other exception types have
a 'Procedure' as well - but not "otherwise uncategorized" exceptions).

Here is a snippet I have in my exception logging routine that writes out the
information. It tells me the name of the specific SQL Server stored
procedure that choked (this is the 'Procedure' you are asking about) and the
specific line number etc. very helpful to have this info:

if (exIncoming is SqlException) {
SqlException e = (SqlException) exIncoming;

//Exception Type
MyWriter.WriteElementString(@"ExceptionType", "SqlException");

// Exception Details
for (int i=0; i < e.Errors.Count; i++) {
MyWriter.WriteStartElement(@"ExceptionDetails");
MyWriter.WriteElementString(@"Message",
HttpUtility.HtmlEncode(e.Errors[i].Message));
MyWriter.WriteElementString(@"LineNumber",
HttpUtility.HtmlEncode(e.Errors[i].LineNumber.ToString()));
MyWriter.WriteElementString(@"Procedure",
HttpUtility.HtmlEncode(e.Errors[i].Procedure));
MyWriter.WriteElementString(@"SQLErrorNumber",
HttpUtility.HtmlEncode(e.Errors[i].Number.ToString()));
MyWriter.WriteElementString(@"SQLServerName",
HttpUtility.HtmlEncode(e.Errors[i].Server));
MyWriter.WriteElementString(@"Provider",
HttpUtility.HtmlEncode(e.Errors[i].Source));
MyWriter.WriteElementString(@"SQLStateValue",
HttpUtility.HtmlEncode(e.Errors[i].State.ToString()));
MyWriter.WriteEndElement(); // End Exception Details
}
}

HTH !
"Denise" <De****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
I am trying to implement database error logging in my asp.net application.
When I inspect the exception variable, I see that there is a property
called
'procedure' which I believe is the procedure or fucntion that caused the
error. How can I get at that variable to write it to my error log?

Thanks,
Denise

Nov 19 '05 #4
Hmm, well there is no Procedure property that I can see. Perhaps you're looking
for:

ex.InnerException.TargetSite.Name

The one thing to note about exceptions in ASP.NET is that there are two categories
in essence. There are the ones your code caused and then there are other
ones that are raised by ASP.NET due to configuration errors and compiler
errors and things like that. When you receive the notification in the Application_Error
event in global.asax you usually check for which category the exception is
in. If it's in the first category then the type of exception thrown is the
HttpUnhandledException. If it's the second category then it's some other
excetionon (ConfgurationException for example). So you tend to write your
code like this:

void Application_Error(Object sender, EventArgs e)
{
Exception ex = Context.Error;
if (ex is HttpUnhandledException)
{
ex = Context.Error.InnerException;
}

// now log ex
}

So if you want the name of the method where the exception was raised, go
look for ex.TargetSite.Name. The other two good pieces of info are Source
which is the assembly and StackTarce which is usually crucial when tracking
down the error. If you just call Exception.ToString() you get all of that
info in a nice neat package. That's what the link I posted was trying to
show :S

-Brock
DevelopMentor
http://staff.develop.com/ballen
Brock,

Thanks for your reply. But perhaps this is not the correct link. I
don't see any mention of referencing the 'procedure' property of an
exception.

Denise

"Brock Allen" wrote:
We recently discussed this over at DevelopMentor's listserv:

http://discuss.develop.com/archives/...L=DOTNET-WEB&P
=R3885&I=-3

http://discuss.develop.com/archives/...L=DOTNET-WEB&P
=R3787&I=-3

-Brock
DevelopMentor
http://staff.develop.com/ballen
I am trying to implement database error logging in my asp.net
application. When I inspect the exception variable, I see that
there is a property called 'procedure' which I believe is the
procedure or fucntion that caused the error. How can I get at that
variable to write it to my error log?

Thanks,
Denise


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Wayno | last post: by
5 posts views Thread by Tony Wright | last post: by
10 posts views Thread by Brian Conway | last post: by
7 posts views Thread by p | last post: by
7 posts views Thread by flupke | last post: by
reply views Thread by Roopesh | last post: by
9 posts views Thread by Rasika WIJAYARATNE | last post: by
2 posts views Thread by =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.