global debug variable?
-
I have logging code that I want to set a global variable for the whole application, something like bool logging = true; I don't want to have to go to all my classes and set this variable. What is the best way to handle this? Can I set it in the web.config file? If so, how? Thanks!
-
I have logging code that I want to set a global variable for the whole application, something like bool logging = true; I don't want to have to go to all my classes and set this variable. What is the best way to handle this? Can I set it in the web.config file? If so, how? Thanks!
You could use compiler directives:
#if DEBUG
// logging code here
#endifThis has the benefit of being compiled out when you go to release code.
α.γεεκ
Fortune passes everywhere.
Duke Leto Atreides -
I have logging code that I want to set a global variable for the whole application, something like bool logging = true; I don't want to have to go to all my classes and set this variable. What is the best way to handle this? Can I set it in the web.config file? If so, how? Thanks!
-
I have logging code that I want to set a global variable for the whole application, something like bool logging = true; I don't want to have to go to all my classes and set this variable. What is the best way to handle this? Can I set it in the web.config file? If so, how? Thanks!
One approach is to create a class that handles the logging and keeps track of whether it's enabled or not, like this:
class Log
{
private static bool m_enabled = System.Configuration.ConfigurationSettings.AppSettings["Logging"] == "true";public static bool Enabled
{
get { return m_enabled; }
}public static void Error(string message)
{
if (Enabled)
// do the logging here
}public static void Info(string message)
....
}Then you can call Log.Error, Log.Info, etc. in your code. For more details on how to use web.config, check out MSDN[^]. Regards, Alvaro
Hey! It compiles! Ship it.
-
One approach is to create a class that handles the logging and keeps track of whether it's enabled or not, like this:
class Log
{
private static bool m_enabled = System.Configuration.ConfigurationSettings.AppSettings["Logging"] == "true";public static bool Enabled
{
get { return m_enabled; }
}public static void Error(string message)
{
if (Enabled)
// do the logging here
}public static void Info(string message)
....
}Then you can call Log.Error, Log.Info, etc. in your code. For more details on how to use web.config, check out MSDN[^]. Regards, Alvaro
Hey! It compiles! Ship it.