views:

111

answers:

4

I have a live web application that is failing in one specific scenario, and locally it works fine. I don't have remote debugging setup, and I want to check the value of some of the variables in the code. What would be the fastest way for me to log/email/debug the code to view those values?

Just to be clear, there is no error/exception being thrown. Something is different, and its causing the application to give unexpected results.

Thanks in advance!

+2  A: 

The fastest way is to simply implement some logging in the Application_Error event within your Global.asax file. If you do not have a Global.asax file, simply create one with the VS New File wizard and it'll handle that event for you.

It won't help you get to local variables at the scope of the error, but you can log global variables from there and at least get some feedback on what the error is.

EDIT: In response to your comment, I recommend you output your Trace data to a file that you can analyze. I haven't tried this myself, but I've seen it recommended. To your web.config, add something called a TraceListener like so:

<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="TestTracer"
type="System.Diagnostics.TextWriterTraceListener, System,
Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
initializeData="<app root directory>\Asptesttrace.log" />
</listeners>
</trace>
</system.diagnostics>

You're going to need to play around with it locally, I'm sure. For instance, make sure the trace is not visible to the client (this may involve using the Trace class to turn the trace on or off, and changing the streams it writes to).

JoshJordan
Sorry, I should have been more specific. There is no exception being thrown, its just that the application is not working as expected. SO the application_error event wont help me.
SkippyFire
In that case, its much more difficult :) One sec, let me edit.
JoshJordan
+1  A: 

In addition to JoshJordan's comment, you may be able to use Post Sharp to trace whenever a method is entered and not exited, and see what values are coming into it...

Yuriy Faktorovich
+1  A: 

You can always turn on local only debugging and then remote on to the server and use the app.

Might be the fastest way to see your problem.

TheAlbear
+1  A: 

I'd try with ASP.NET trace (http://www.4guysfromrolla.com/webtech/081501-1.shtml) for quick logging. You will have to add Trace.Write() calls in your code and you can see the log in the live page itself (just by browsing).

For richer logging you can use log4net (just google "using log4net" and you'll get loads of useful links), which is easily configurable and allows you to send logs via email (which is amazingly handy!).

Hope that helps.

antur123