Last post Jan 12, 2010 12:22 PM by atconway
Jan 07, 2010 04:08 PM|xmlapi|LINK
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).
Jan 07, 2010 05:17 PM|SpongeBert|LINK
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();
Jan 08, 2010 09:43 AM|xmlapi|LINK
No, I want the Page Trace Output as in Trace.Write("test") output along with the exception.
Jan 08, 2010 09:56 AM|uid639299|LINK
Jan 08, 2010 04:06 PM|dotnetkode|LINK
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.
Jan 10, 2010 07:24 AM|SpongeBert|LINK
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;
Jan 12, 2010 12:22 PM|atconway|LINK
From the following:
"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):
Tracing in ASP.NET:
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: