Skip to content
DataMiner DoJo

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages
Search in posts
Search in pages
Log in
Menu
  • Updates & Insights
  • Questions
  • Learning
    • E-learning Courses
    • Empower Replay: Limited Edition
    • Tutorials
    • Open Classroom Training
    • Certification
      • DataMiner Fundamentals
      • DataMiner Configurator
      • DataMiner Automation
      • Scripts & Connectors Developer: HTTP Basics
      • Scripts & Connectors Developer: SNMP Basics
      • Visual Overview – Level 1
      • Verify a certificate
    • Video Library
    • Books We Like
    • >> Go to DataMiner Docs
  • Expert Center
    • Solutions & Use Cases
      • Solutions
      • Use Case Library
    • Markets & Industries
      • Media production
      • Government & defense
      • Content distribution
      • Service providers
      • Partners
      • OSS/BSS
    • Agile
      • Agile Webspace
      • Everything Agile
        • The Agile Manifesto
        • Best Practices
        • Retro Recipes
      • Methodologies
        • The Scrum Framework
        • Kanban
        • Extreme Programming
      • Roles
        • The Product Owner
        • The Agile Coach
        • The Quality & UX Coach (QX)
    • DataMiner DevOps Professional Program
      • About the DevOps Program
      • DataMiner DevOps Support
  • Downloads
  • More
    • DataMiner Releases & Updates
    • Feature Suggestions
    • Climb the leaderboard!
    • Swag Shop
    • Contact
    • Global Feedback Survey
  • PARTNERS
    • All Partners
    • Technology Partners
    • Strategic Partner Program
    • Deal Registration
  • >> Go to dataminer.services

How to conditionally compile logging information in an automation script

Solved959 views18th July 2023
3
Gelber Mahecha [SLC] [DevOps Enabler]1.62K 21st October 2021 0 Comments

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?

Marieke Goethals [SLC] [DevOps Catalyst] Selected answer as best 18th July 2023

2 Answers

  • Active
  • Voted
  • Newest
  • Oldest
0
Gellynck Jens [SLC]2.71K Posted 22nd October 2021 1 Comment

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.

Marieke Goethals [SLC] [DevOps Catalyst] Selected answer as best 18th July 2023
Gelber Mahecha [SLC] [DevOps Enabler] commented 22nd October 2021

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?

0
Gellynck Jens [SLC]2.71K Posted 22nd October 2021 0 Comments

To actually verify if the “Compile in using debug mode” is checked, you can use the following code:

var scriptInfo = engine.SendSLNetSingleResponseMessage(new GetScriptInfoMessage(“your script name here”)) as GetScriptInfoResponseMessage;
bool isDebug = scriptInfo.Exes[0].CSharpDebugMode;

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.

Gellynck Jens [SLC] Edited answer 22nd October 2021
Please login to be able to comment or post an answer.

My DevOps rank

DevOps Members get more insights on their profile page.

My user earnings

0 Dojo credits

Spend your credits in our swag shop.

0 Reputation points

Boost your reputation, climb the leaderboard.

Promo banner DataMiner DevOps Professiona Program
DataMiner Integration Studio (DIS)
Empower Katas
Privacy Policy • Terms & Conditions • Contact

© 2025 Skyline Communications. All rights reserved.

DOJO Q&A widget

Can't find what you need?

? Explore the Q&A DataMiner Docs