C# .NET – Displaying debug information in Debug compilation

If you want to output extra infromation in your code to see what is going on in problem situations and you only want to include it in debug compilations and not in Release version you can add a “Debug” Conditional attribute to a function and use that function to output data into your system output. There are many ways but this is a simple and straightforward way to do it:

[Conditional(“DEBUG”)]
private void DebugInfo(String info)
{
#if DEBUG
Response.Write(“</br>” + info);
#endif
}

The function and it’s content will be left out in Release compilation.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s