Tip #28 – WriteLog() – The Easy Way to Display Debugging Information in ASP.NET



Tip #28 – WriteLog() – The Easy Way to Display Debugging Information in ASP.NET

LearnVisualStudio is currently having a sale on all of its memberships. Click on the link below to receive your discount now:

Get LearnVisualStudio at 15% off now

Tip #28 – WriteLog() – The Easy Way to Display Debugging Information in ASP.NET

It can often be difficult to display information in ASP.NET because System.Diagnostics, Response.Write, or the Trace object are not available – for example, when you are working in the global.asax or inside a class.

A simple way to display what lines are executing and what information is in a given field is by creating a simple  WriteLog() method in a class in the App_Code folder. Then, when you want to display the contents of a field anywhere in your program, you just use:

C#:
clsWriteLog.WriteLog("strXyz: " + strXyz);

VB.NET:
clsWriteLog.WriteLog("Line 203 executed")

You have two ways to view what is written to the log:

1. While in Visual Studio, you look at trace.log file in your root directory.

2. While in the website, you type http://www.yourwebsitename.com/trace.log

You can download the few lines of code for the class  clsWriteLog at clsWriteLog.  The code for the class is provided in vb.net and c#.


Code Samples


FFMPEG Hosting with AptHost

I highly recommend AptHost for hosting non-ASP.NET websites – like blogs, etc. IdealProgrammer.com and IdealProgrammer.tv both use AptHost as the hosting provider. AptHost provides a very economical solution, and their support team is "second-to-none."

Get LearnVisualStudio at 15% off now