Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > NAnt
NAnt For discussing the NAnt .NET build tool. When posting a question, please specify the version of NAnt you are using.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the NAnt section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 3rd, 2011, 07:47 AM
Registered User
Join Date: Aug 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Nant Logger problem

I need to create log file for my each build and for this I'm using command line as
nant -logfile:output.txt -buildfile:my.build -D:client.name=xyz-D:branch=abc

So above command is generating log file at same location at which my build script "my.build" is running (let say C:\build) and log file (output.txt) is Ok and contains all the required data

but I want to move Or copy each of generated log files to new location which will be created by variable are passed to script and for this I'm using below target to copy log to new directory

<target name="build">

<mkdir dir="${logger.dir}" if="${not directory::exists(logger.dir)}" />
<some command to compile solution>
<copy file="C:\build\output.txt" tofile="${logger.dir}\webbuild.${build.date}.txt" overwrite="true"/>


above target is copying empty webbuild.${build.date}.txt without any data.

I did some investigation and found that since nant is using output.txt in above commandline (i.e nant -logfile:output.txt -buildfile:my.build -D:client.name=xyz-D:branch=abc) so It's not allowing to me to copy Or move output file to new location.

Can anyone suggest me some solution for this ..As what approch I should follow to make this posible.

note : after my commandline completes then only I can copy the file..but i need to copy/move generated log file to new location at one go using same above commandline


Last edited by raju.sathliya; August 3rd, 2011 at 07:55 AM..
Old August 3rd, 2011, 10:58 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

You should use the <record> nant task instead. The logfile command line argument simply redirects the command line output to a log file. The record task lets you control what and how the build output is recorded. You can specify the file name using standard nant property syntax so it's variable. Usually, you'd start recording very early on outside of any targets so that it starts regardless of the called target. Then you use the built in "nant.onsuccess" and/or "nant.onfailure" properties to specify targets to run in each case. Use these targets to close the recording. I have a separate target to "finalize" the build log to minimize repetition.

Here are the relevant bits from a build file I use...

<project ... >

	<record name="${path.buildLog.file}" action="Start" />

	<property name="nant.onsuccess" value="onSuccess"/>
	<property name="nant.onfailure" value="onFailure" />

	<!-- other targets -->

	<target name="onSuccess">
		<echo message="Build Succeeded." />
		<call target="finalize" />

	<target name="onFailure">
		<echo message="Build Failed." />
		<call target="finalize" />

	<target name="finalize">
		<!-- other cleanup stuff here -->
		<record name="${path.buildLog.file}" action="Close" />

The Following User Says Thank You to planoie For This Useful Post:
raju.sathliya (November 16th, 2011)
Old November 16th, 2011, 11:15 AM
Registered User
Join Date: Aug 2011
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thanks Peter !! It's working fine now

Thanks Peter !! It's working fine now
Old May 1st, 2015, 03:57 PM
Registered User
Join Date: May 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

If I need to log error reason message on failure. I do not want entire log details and just want to log error message to different log file.
Will Record task help?

Similar Threads
Thread Thread Starter Forum Replies Last Post
NAnt - External Program Failed mercurysmiles NAnt 1 November 20th, 2008 10:40 AM
how to connect to remote machine using nant kalpana2009 NAnt 0 October 8th, 2007 07:25 AM
Building web application using NANT ydevesh NAnt 0 November 17th, 2006 09:30 AM
Logger.getInstance in Action Class ramanadyv Struts 1 January 16th, 2006 05:44 AM
ViewState Size Logger mohandeval Classic ASP Basics 0 August 16th, 2005 02:58 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.