Overview of Logging in MSBuild
MSBuild loggers provide a way to customize the reporting of build events, messages, warnings, and errors. Loggers can display information in the console window, write to XML or a text file, or enter build data into a database.
A logger is used to relay the information from build events, messages, warnings, and errors to a log that is easily read and interpreted. The logic of a logger is written in a managed type that implements the ILogger interface.
When you run MSBuild.exe from the command line, MSBuild uses the default console logger to display build event information in the console window. You can customize the level of detail that you want the logger to report by using the /verbosity switch on the command line.
The default console logger accepts additional parameters that can modify the output to the console window. These parameters are specified with the /consoleloggerparameters switch on the command line.
If you are using a custom logger, you may want to hide the information displayed from the default console logger. Use the /noconsolelogger switch on the command line to disable the default console logger.
MSBuild also includes a file logger that logs build event information to a file. To run the file logger, use the following switch at the command line, where MyLog.log is the file in which to store the log information.
/l:FileLogger,Microsoft.Build;logfile=MyLog.logIn total, the file logger also accepts four parameters. These are:
Logfile: A required parameter that specifies the file in which to store the log information.
Append: An optional boolean parameter that indicates whether or not to append the log to the specified file: true to add the log to the text already present in the file; false to overwrite the contents of the file. The default is false.
Verbosity: An optional parameter that overrides the global verbosity setting for this file logger only. This enables you to log to several loggers, each with a different verbosity.
Encoding: An optional parameter that specifies the encoding for the file, for example, UTF-8.
Multiple parameters are separated with semicolons (;). For example, the following command line logs the build event information to the file MyLog.log, and appends the log to the text in the file, with diagnostic verbosity, and with UTF-8 encoding.
MSBuild MyProj.proj /l:FileLogger,Microsoft.Build.Engine;logfile=MyLog.log; append=true;verbosity=diagnostic;encoding=utf-8
If you want to use a logger other than the default console logger during a build, specify the custom logger using the /logger switch on the command line. For more detailed information on MSBuild command line switches, see MSBuild Command Line Reference.