Killer Nant Scripting Part 6: Logging

Demistyfiying the Black Box

Logging is logical extension of creating usable output from any type of computer program, be it a windows GUI, a web application, or even a script. Logging allows us to get into the nitty gritty about important steps our programs are executing. This goes one step further into creating really polished, functional scripts. Once we can track what is going on we remove some of the mystery of what is going on.

There are two ways to log, one is through the command line, and the other is the task made available through the NAnt contrib library. The task allows us to save portions of our scripts to files.

To call the record task, we pass it the path of the log file, which we specified with a global variable for the directory, and local action variable and the parameter action=”start” to start the recording task, and then we call it again after the actions we wish to log, and but with the action=”Close” property.

Record Task Example:<!-- Start Logging --><record name="${global.log.dir}\${action.log.file}" level="Info" action="Start"/>

<someaction .../>

<!-- End Logging --><record name="${global.log.dir}\${action.log.file}" action="Close"/>

If you wish to log without using the NAnt contrib library, you can use a simple solution, at the command line redirect the output using ‘>’ . We can redirect the output to a file and save it.

Run our script from the command line normally, but then append > “mylog.txt” to log the output.

Use -e (emacs ouput) to remove some of the excessive NAnt output artifacts.

C:\> nant /f:buildscript.build -e /v:+ all > "mylog.txt"

This will redirect the output of the build script to mylog.txt.

View All of the Killer Nant Scripting Articles

Post a Comment

Your email is never shared. Required fields are marked *

*
*
Profile Picture

About Ian Lintner


I am a software developer, mostly web,  in Des Moines, Iowa. I take a very opinionated stand concerning development, you will never regret a simple design or architecture. My education was at Drake University in Biology and Computer Science. Offline I am recently married to my wife Heather. I try my hand at many hobbies currently I am gardening till the snow comes in.



My Current Projects


Des Moines Twitter Trends