I am using FileLogger to log event from msbuild to a file. How can i concatenate datestamp to the logfile name
msbuild.exe MSBuildCommunity.proj /l:FileLogger,Microsoft.Build.Engine;logfile=MSBuild.log
i want logfile name to be MSBuild_yyyymmdd.log
thanks

concatenate datestamp to logfile name
Gjergji Stasa
There's no way to do this with our built-in file logger. You'd need to either write a custom logger that knows how to do this (the "correct" way) or wrap the call to MSBuild in some sort of script that knows how to find the current date and append it to the command line (the "cheap and easy" way).
Neil
larsbg
Writing a custom logger is really easy. Check out the following blog topic for details:
http://blogs.msdn.com/msbuild/archive/2005/10/10/479223.aspx
Neil
rusty coder
When you write a custom logger you are responsible for doing the formatting of the messages yourself. That's likely why they didn't look the same as the console logger.
Sayed has an example up where he subclasses the file logger to do extra processing, but still lets the file logger do all the log writing. Check it out at http://www.sedodream.com/PermaLink,guid,48b277b0-9d2f-4eb0-8186-f0b103a6da67.aspx.
Neil
Tom C.
I tried writing custom logger inherited from ConsoleLogger which handles AnyEventRaised event and write the messages to a text file. Messages logged in the text file are not similar to what are displayed on the console.
When you run MSBuild.exe with FileLogger
MSBuild.exe myProject.proj /l:FileLogger,Microsoft.Build.Engine;logfile=c:\temp\logs\MSBuild.log
The messages shown on the console are logged to the MSBuild.log file. How can I make my custom logger to log the messages as displayed on the console
Thanks
Rajeev Mehta
I threw the following in a batch (.bat) file and call msbuild with that, but that does not format the date/time nicely so I'll following this thread in hope for better suggestions
msbuild BuildLab.proj /l:FileLogger,Microsoft.Build.Engine;logfile="logs\Build %date%--%time::=-%.log"
mikesql
neil
the event agrs in logger class shows different messages than what is displayed on the console when you run MSBuild.exe how can i capture the messages displayed by msbuild.exe on console in my custom logger.
Thanks
SaschaK
-pk
hi simon in case u r interested this is how i did it
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using System.IO;
namespace MSBuildLoggers
{
public class TextFileLogger: FileLogger
{
public override void Initialize(Microsoft.Build.Framework.IEventSource eventSource)
{
this.MoveLogFile();
base.Initialize(eventSource);
}
void MoveLogFile()
{
string currentDir = System.Environment.CurrentDirectory;
string logFile = string.Format("{0}{1}", currentDir, @"\msbuild.log");
if (File.Exists(logFile))
{
// Get previous date.
DateTime previousDate = DateTime.Today.AddDays(-1);
// Rename the exisiting log file.
string renamedLogFile = currentDir + string.Format(@"\Logs\msbuild_{0}{1}", previousDate.ToString("yyyyMMdd"), ".log");
if (! File.Exists(renamedLogFile))
{
// Move renamed log file to Logs folder.
File.Move(logFile, renamedLogFile);
}
}
}
}
}
MoveLogFile method appends previous date to msbuild.log file and moves it to Logs folder.