New Terminal logger for .NET 8

31/05/2023

With preview 4 of .NET 8, a new terminal logger was introduced. It basically removes a lot of the noise that the default logger produces. It also adds some nice colors to the output. Let's see how to use it!

The old way

Imagine we have the following code:

Console.WriteLine("Hello World!"1);

Obviously this is not compilable, so if we invoke: dotnet build we get the following output:

MSBuild version 17.7.0-preview-23251-02+59879b095 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
/usr/local/share/dotnet/sdk/8.0.100-preview.4.23260.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/Users/stgi/repos/ConsoleApp1/ConsoleApp1.csproj]
/Users/stgi/repos/ConsoleApp1/Program.cs(1,18): error CS1003: Syntax error, ',' expected [/Users/stgi/repos/ConsoleApp1/ConsoleApp1.csproj]

Build FAILED.

/Users/stgi/repos/ConsoleApp1/Program.cs(1,18): error CS1003: Syntax error, ',' expected [/Users/stgi/repos/ConsoleApp1/ConsoleApp1.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.57

Okay we see it did fail, but why and where? Remember this is just a very small sample, imagine you have a big application with maybe mutliple errors!

The new way

Let's try the same with the new terminal logger. For that we just add the --tl flag to the dotnet build command:

dotnet build --tl
The output is:
MSBuild version 17.7.0-preview-23251-02+59879b095 for .NET
Restore complete (0.3s)
  ConsoleApp1 failed with errors (0.2s)
    ? /Users/stgi/repos/ConsoleApp1/Program.cs(1,18): error CS1003: Syntax error, ',' expected

Build failed with errors in 0.6s

We get colors, and an icon pointing directly in the right direction! But not only that, but if your terminal supports it, it has a nice new way of indicating what is going on:

terminal

## GitHub Actions If you are using GitHub Actions, the new logger will not do much for you in addition. I will directly quote the docs from msbuild here:

The environment check verifies that the terminal is capable of using modern output features and isn't using a redirected standard output before enabling the new logger.

Unfortunately, GitHub Actions does redirect the standard output, so we don't get the nice new features.

Conclusion

The new logger is a great improvement over the old one. It is much easier to read and understand. If you want to know more, check out the official documentation.

5
An error has occurred. This application may no longer respond until reloaded. Reload x