I create a Windows application in VS 2010 C#. It is a web crawler application and using the N tier application structure (One Windows application and many class libraries in this project). Last week i implement a Log system in all projects for creating log text for solve performance issues. But now i want to disable this log functions in Release Mode.
I googled and get a example from CodeProject. Please see my code below.
public class ModeDetector
{
public virtual bool IsDebug
{
get
{
bool isDebug = false;
#if (DEBUG)
isDebug = true;
#else
isDebug = false;
#endif
return isDebug;
}
}
public bool IsRelease
{
get { return !IsDebug; }
}
}
I create this class in my base class library. for get this class for all reference projects. I call this method in my Windows application. like
if (new Sun.lib.ModeDetector().IsDebug)
MessageBox.Show("Debug Mode");
else
MessageBox.Show("Release Mode");
and change my project Build Configuration to " Release " . But this code is always shows the " Debug Mode " message. But when i create this class in my windows application it's works fine. But i am too worry about to create this class in every project.
Please advise me what is the best practices to determine a project(s) is work debug or release mode. How can i use this class in entire project.
Edits :
I refer the class library in the Debug bug folder of class library project.
my class libraries and win forms applications are lie on the same solutions.
Thank you Marcus. I follow your instruction and rewrite my code like:
#if (DEBUG)
MessageBox.Show("Debug Mode");
#else
MessageBox.Show("Release Mode");
#endif