I am trying to enhance my Logger class with some conditionals to control what to log and where to log. I've got two kinds of logging functions:
public static class Logger
{
[Conditional("Logging"), Conditional("VerboseLogging")]
public static void Log(string msg, string filename)
{
// log to file
}
[Conditional("VerboseLogging")]
public static void VerboseLog(string msg, string filename)
{
Log(msg, filename); // just defer call to Log(string msg)
}
}
However, running the following program
#define Logging
#define VerboseLogging
static void Main(string[] args)
{
Logger.Log("Logging", "");
Logger.VerboseLog("VerboseLogging", "");
}
yields only the output "Logging", missing "VerboseLogging".
Debugging the application showed that VerboseLogging indeed does get called, but it does not call Log(msg, filename)
. The debugger simply jumps right over the function call to the end of the VerboseLog()
function.
When I remove the conditionals from the Log(string msg)
method, it works.
Does anybody have a clue as to why this happens or what to do so it will be called?