Answered by:
Logging exceptions

Question
-
User2090782264 posted
How do I log an exception and it's trace (page) to a log directory?
I can already log the exception by using the HttpWebException class but what about the trace output of the page? (do not want to use any third party tools).
Thursday, January 7, 2010 4:08 PM
Answers
-
User-952121411 posted
From the following: http://www.4guysfromrolla.com/articles/121008-1.aspx
"Tracing can be configured at the page-level through the Trace attribute in the @Page directive, or can be configured for the entire web application using the <trace> element in Web.config.
Having tracing enabled in a production environment is ill advised because the trace log displays sensitive information including cookies, information stored in session state, and any diagnostic information written to the trace log. With tracing enabled, a malicious user could visit the Trace.axd page and see the trace logs for the last several requests to the application.
To change trace information from appearing you can either disable tracing altogether or configure it so that it's only accessible when coming through localhost. The <trace> element has two Boolean attributes that specify these particular settings: enabled and localOnly. For more information see the <trace> element technical documentation and Tracing in ASP.NET. "
trace Element (ASP.NET Settings Schema):
http://msdn.microsoft.com/en-us/library/6915t83k.aspx
Tracing in ASP.NET:
http://www.4guysfromrolla.com/webtech/081501-1.shtml
TraceSection Class:
http://msdn.microsoft.com/en-us/library/system.web.configuration.tracesection.aspx
You may want to look at the 'writeToDiagnosticsTrace' element of the trace configuration. You could then get the trace from a registered listener.
Debugging and Tracing in ASP.NET:
http://www.webreference.com/programming/asp/debugging/3.html
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, January 12, 2010 12:22 PM
All replies
-
User-492280791 posted
Hi xmlapi,
Try this in your global.asax and you get all traces:
void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs Exception objErr = Server.GetLastError().GetBaseException(); string err = "" + "<br><b>Error Message: </b>" + objErr.Message.ToString() + "<br><b>Stack Trace:</b><br>" + objErr.StackTrace.ToString(); mySecurity.Security.Inserterrorlog(err.ToString()); //Server.ClearError(); }
Thursday, January 7, 2010 5:17 PM -
User2090782264 posted
No, I want the Page Trace Output as in Trace.Write("test") output along with the exception.
Friday, January 8, 2010 9:43 AM -
Friday, January 8, 2010 9:56 AM
-
User-1067358373 posted
If you enabled Tracing at the application level, you can access Trace information by going to Trace.axd from the root of your application.
I'm not sure how to log Trace data but the data can get huge in a short period of time and I dont think thats a good idea.
Friday, January 8, 2010 4:06 PM -
User-492280791 posted
Hi,
But this in your global.asax and you can manually add querystring to see trace to every page in your project:
void Application_BeginRequest(object sender, EventArgs e) { if (Context.Request.QueryString["trace"] != null && Context.Request.QueryString["trace"].ToString() != "") { if (Context.Request.QueryString["trace"].ToString() == "true") { Context.Trace.IsEnabled = true; } } }
Sunday, January 10, 2010 7:24 AM -
User-952121411 posted
From the following: http://www.4guysfromrolla.com/articles/121008-1.aspx
"Tracing can be configured at the page-level through the Trace attribute in the @Page directive, or can be configured for the entire web application using the <trace> element in Web.config.
Having tracing enabled in a production environment is ill advised because the trace log displays sensitive information including cookies, information stored in session state, and any diagnostic information written to the trace log. With tracing enabled, a malicious user could visit the Trace.axd page and see the trace logs for the last several requests to the application.
To change trace information from appearing you can either disable tracing altogether or configure it so that it's only accessible when coming through localhost. The <trace> element has two Boolean attributes that specify these particular settings: enabled and localOnly. For more information see the <trace> element technical documentation and Tracing in ASP.NET. "
trace Element (ASP.NET Settings Schema):
http://msdn.microsoft.com/en-us/library/6915t83k.aspx
Tracing in ASP.NET:
http://www.4guysfromrolla.com/webtech/081501-1.shtml
TraceSection Class:
http://msdn.microsoft.com/en-us/library/system.web.configuration.tracesection.aspx
You may want to look at the 'writeToDiagnosticsTrace' element of the trace configuration. You could then get the trace from a registered listener.
Debugging and Tracing in ASP.NET:
http://www.webreference.com/programming/asp/debugging/3.html
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, January 12, 2010 12:22 PM