Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a C# preprocessor directive from a central file?

Tags:

c#

I need to add some logging to my app, and it needs to be in release mode, and I need to make sure that the logging code isn't running in production. Therefore I'd like to use a #define and #if to make sure the log statements are removed when I move to production.

Trouble is, I need the logging in multiple files, and it's a pain to put a #define at the top of every file. Is there a way to have a centralized #define? That way I can remove the single #define rather than a #define from all files(which means I'll almost assuredly forget one).

like image 711
Jonathan Beerhalter Avatar asked Dec 14 '11 17:12

Jonathan Beerhalter


People also ask

Can we keep AC at 29 degrees Celsius?

24-30 degree celsius is the ideal temperature for your AC, says CPWD in a guideline - India News.

Can I run AC at 30 degrees Celsius?

It is absolutely safe to use ACs of all types. One should set the temperature between 24 to 30 degrees centigrade. The humidity is automatically taken care of. In central ACs, fresh air ventilation is part of the AC system.

Is higher or lower colder on AC?

Lower Thermostat Cooler Home. One of the biggest misconception homeowners have about their central air system is that a lower number on the thermostat indicates colder air. This is technically untrue. If you find yourself asking, “does a lower thermostat cool my home more quickly,” we can answer that for you.

What is best temperature for AC?

According to the Department of Energy1, 78° Fahrenheit is the sweet spot for air conditioners to balance energy savings and comfort when people are at home and need cooling.


1 Answers

On the command line, use the /define switch. In Visual Studio, choose the "Build" tab from the properties page for the project and fill in the "Conditional Compilation Symbols" section.

Consider also instead of using conditional compilation, to instead make your logging methods conditional methods. That's a more pleasant-looking alternative. That's how Debug.Assert works; it is a conditional method, so if the debug preprocessor symbol is not defined, the compiler simply removes all calls to the method before code generation.

See also my article on the subject:

http://ericlippert.com/2009/09/10/whats-the-difference-between-conditional-compilation-and-the-conditional-attribute/

like image 69
Eric Lippert Avatar answered Nov 21 '22 13:11

Eric Lippert