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.

.NET 8 and Blazor United / Server-side rendering

New .NET and new Blazor features. In this blog post, I want to highlight the new features that are hitting us with .NET 8 in the Blazor world. So let's see what's new.

ReadOnlySet<T> in .NET 9

The next preview (preview 6) will bring a new type ReadOnlySet<T>. This is a read-only set that is similar to ReadOnlyCollection<T>. Let's see how it works and why it was introduced.

New ArgumentException and ArgumentOutOfRangeException helpers in .NET 8

Do you remember how .NET 6 introduced the ArgumentNullException.ThrowIfNull guard? And afterward, with .NET 7 we've got this excellent bit: ArgumentException.ThrowIfNullOrEmpty? Guess what, there might come some new handy additions for the upcoming .NET 8 iteration.

So let's see what are those new changes and how they make the code simpler.

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