Max
Max

Reputation: 13388

Switch between Release and Debug in code

I published my application and I want to add extra "Admin" functionality to it. I see a lot of debug information, when I run my application in Debug mode, all of this is removed in the Release mode, for having a more clear application.

Now if I login to my application, I want to check the login name and password, so for example when I login with "Admin", "Password", I want to see the Debug info as well.

Question:

Is it possible to switch from Release to Debug in code?

Upvotes: 2

Views: 1626

Answers (2)

TToni
TToni

Reputation: 9391

That depends on how you render that additional information in debug mode. If you enclosed it in "#ifdef DEBUG" the code is not compiled in a release build, so since it is not in the dll, it cannot be executed.

To get debug information into a release build basically you have to replace

#if DEBUG
    OutputSomeDebugInfo();
#endif 

with

if (GlobalFlags.IsDebugMode)
{
    OutputSomeDebugInfo();
}

where "GlobalFlags" is a static public class you have to create with a static bool member or property "IsDebugMode" which would be only set to true when you use the admin login or when you do a debug build.

Logging and tracing tools like log4net or from the enterprise library are designed to give you finegrained, configurable control over what is logged in your application, so you may want to check out these too.

Upvotes: 1

harriyott
harriyott

Reputation: 10645

The short answer is no, because the compiler generates different assemblies for debug and release builds. Some code may be missing, if a developer had added compile-time conditional code, e.g.

#if DEBUG
    DisableSharingWithPrism();
#endif

would only run compile the code in the debug code. In release mode, the code would not be present.

To get round this, write a method to work out if the user is an administrator, and find and replace the #if DEBUG calls with this method, for example:

if (UserIsAdmin())
{
    DisableSharingWithPrism();
}

Upvotes: 2

Related Questions