p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   NAnt (http://p2p.wrox.com/forumdisplay.php?f=367)
-   -   Nant Logger problem (http://p2p.wrox.com/showthread.php?t=84572)

raju.sathliya August 3rd, 2011 07:47 AM

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


planoie August 3rd, 2011 10:58 AM

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" />


raju.sathliya November 16th, 2011 11:15 AM

Thanks Peter !! It's working fine now
Thanks Peter !! It's working fine now

Jigisha May 1st, 2015 03:57 PM

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?

All times are GMT -4. The time now is 05:05 PM.

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