An introduction to the concept of pruning is given in FAQ: What is Pruning?.
Since Version 5, the Microsoft C# compiler supports methods to be annotated with class "ConditionalAttribute". This attribute uses a conditional compilation symbol which causes the compiler to ignore the invocation of methods when the symbol is not set. Again: the invocation of the methods is disabled, not the compilation of the methods itself!
Consider the following line of code:
Method Log.SetVerbosity() is annotated as conditional using the symbol ALOX_DBG_LOG. Now the compiler does not include this line into the executable when ALOX_DBG_LOG is not set.
However, the compiler still checks the integrity of the parameter. Therefore, ALox provides empty method stubs for the most common classes and a few of their methods, even in the release configuration. To be able to compile the sample above in release mode, we need
In the release version, both are empty "stubs" of their original classes. The reason why ALox creates stubs is to minimize the footprint of ALox in the moment it is not used (in the deployed applications that do not do release logging). Members of classes that are not too frequently used are not available in the release.
Consider the following code to setup the format of a log line:
This would lead to a compilation error in the release configuration of your project (if you do not use release logging). The reason is, that the field MetaInfo is not included in the release version of ALox. In fact, the whole class MetaInfo is not existing!
To resolve this, use conditional compilation for all non-standard code specific to ALox logging:
While this is sufficient, in the last sample, when compiled in release configuration, there is an almost empty version of ConsoleLogger still created and never used. Therefore, you might want to do it like this:
This sample shows, that only for the configuration/bootstrap part your code gets "cluttered" with #if
...
#endif
statements. And: As long as you do not get compiler errors in the release version, you can trust ALox that the impact of remaining configuration code is minimal. Again: standard logging code is always removed 100%!
The result of the things said above incorporate six great news for you:
#if
... #endif
statements!#if
... #endif
statements if using ALox! Only within some "bootstrap sections".