8

If I want to specify a logger where I can set the name and location of the log file, I do the following:

dotnet build /l:FileLogger,Microsoft.Build.Engine;logfile=MyLog.log

This syntax has worjked for me in the past with msbuild, however it is not working with dotnet. What am I doing wrong?

enter image description here

2 Answers 2

24

I took me some time to find this, but you can use fileloggerparameters (flp)

dotnet build /flp:v=diag

This will create log file msbuild.log. The Option [v]erbosity is set to [diag]nostic. But you can choose others verbosity levels.

Use the option logfile to specify the name of the log file.

dotnet build /flp:v=diag;logfile=MyLog.log

This also works with msbuild

msbuild /flp:v=diag;logfile=MyLog.log

Using Powershell the command for dotnet looks like

dotnet build /flp:v=diag /flp:logfile=MyLog.log
4
  • 1
    I get this output when I run what you suggest: logfile=MyLog.log : The term 'logfile=MyLog.log' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:26 + dotnet build /flp:v=diag;logfile=MyLog.log + ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (logfile=MyLog.log:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
    – Noel
    Commented Feb 1, 2018 at 13:31
  • @Noel so you are using powershell. I tried it with normal CommandLine.
    – Jehof
    Commented Feb 1, 2018 at 13:36
  • @Jehof Thanks for finding this! It would be very valuable to link to some documentation, because even today, it seems very hard to find. Thanks!
    – Oliver
    Commented Jan 18, 2022 at 12:59
  • 1
    if you are using dotnet in powershell, then use with quotes. e.g. -flp1:"logfile=errors.txt;errorsonly"
    – goldcode
    Commented May 27 at 11:51
1

Maybe the way I went thru will help others to find out and test other parameters for dotnet commands.

I was searching that before at dotnet command reference at https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet but failed.

Details of using fileloggerparameters are well documented at https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2022#:~:text=%E2%80%91-,fileLoggerParameters,-%5Bnumber%5D%3A I dind't test if all params of MSBuild apply to dotnet but at least I sucessfully tested those related to logging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.