top of page
  • Black LinkedIn Icon
  • YouTube
  • Gateway Scripts
  • Whatsapp

First Experiences Logging with NLog


Logging is an important part of application development. Logging can help you identify how your users are using your software tools, help debug if the ESAPI thrown application errors are not immediate clear, and assist in retrospective studies of application use. As more of my applications that I work on continue to have automation components, I've been trying to be more consistent with logging times when automation is triggered and at what step the user is currently occupying within the planning process.


In a latest application, I tried using NLog, which I hadn't used before. I found the NLog to be simple and intuitive, and the log format works well.


Instructions for using NLog can be found here https://github.com/NLog/NLog/wiki/Tutorial Following these instructions, I set up the NLog.config file to have the date in the filename.


Below is the access tot he static Logger class, and a simple use case. The use case describes setting the target volume for a plan. In this example the method SetTargetStructureIfNoDose allows for the input of a StringBuilder object to hold any error messages that may arise from exceptions thrown in the method.



And just like that, we have our log file output!



 
 
 

1 Comment


mschmidt33
May 20, 2023

One update to this that I would like to emphasize, since I just started another application, and ran into this as an issue. The NLog.config file must be set to "Copy if newer" in the properties of the file because it must be in the output location for the application to write the log files.

Like

©2035 by NWS. Powered and secured by Wix

bottom of page