When developing automation scripts, it is usual to add logging lines (either to the information console or the automation log) for troubleshooting purposes.
It could be great to conditionally add this logging based on the Compile in DEBUG mode setting:
Currently, I'm using a symbol definition (#define DEBUG) to include or exclude the logging. Is there a way to use the DEBUG mode setting instead?
Besides using the DEBUG define, you could check at runtime if the current assembly is compiled in DEBUG with the following code:
var assembly = Assembly.GetExecutingAssembly();
bool isDebug= assembly.GetCustomAttributes(false).OfType<DebuggableAttribute>().Any(da => da.IsJITTrackingEnabled);
engine.GenerateInformation("Debug? " + isDebug);
Based on this isDebug boolean the script can then decide whether or not to call engine.Log or engine.GenerateInformation.
note: This is an internal call and we do not recommend using this, as it is not officially supported and we cannot guarantee that it will still work in the future. As a rule, you should avoid using SLNet calls, as these are subject to change without notice.
Thanks Jens. Because this is a runtime verification, it will include in the compiled assembly, code that will check every time if the logging is required or not.
Seems to be the best option by now is to keep using a preprocessor to define (or not) the DEBUG symbol. Could this be an interesting feature?