0

Hello I am working on a Server Application that is multithreaded having a control panel form and a console for the output. I am using log by console output. For Enabling log I compile the version with log and for disabling log I compile the version without log. This is handled as I use all code is between the lines.

#if Enable_DEBUG_ECHO
Console.WriteLine("Something is happening");
#endif

so I if use #define Enable_DEBUG_ECHO on top of file it compiles for echo. But I want implement a option by which user can enable/disable log by single click or something like that. Somebody give me the idea how can I do this.

Leri
  • 12,367
  • 7
  • 43
  • 60
M Naeem Ashraf
  • 241
  • 2
  • 9

2 Answers2

2

You know, when u are using precompile options (such as your code), the program contains only code one 'version' of code (I mean, that if you define Enable_DEBUG_ECHO, line 'Console.WriteLine("Something is happening");' will included in result dll, but it will not included if you don't define Enable_DEBUG_ECHO).

So if u want to enable/disable your log in runtime, u should create your log without precompile options.

So u need to save your 'turn on/off' variable in configuration file. And than

if (VARIABLE_FROM_CONFIG)
{
Console.WriteLine("Something is happening");
}
Udgin
  • 119
  • 2
  • 9
1

You can use a logging framework such as NLog or log4net, that makes all this so easy. You can configure them programatically or through configuration files.

Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72