Skip to content

Logger Configuration

Arun Mahapatra edited this page Jan 31, 2021 · 1 revision

Logger Configuration

junit, nunit and xunit loggers support the following common options. Options can be specified in the commandline as follows:

# Replace xunit with the relevant logger name
# > dotnet test --logger:"<loggername>;<option>=<value>"
> dotnet test --logger:"xunit;LogFileName=mytestresults.xml"

Available options are documented below.

LogFileName

Use LogFileName to specify the name of the output log file. The file will be created in the default results directory (TestResults) relative to test project.

LogFileName accepts token expansion. E.g. you can provide {assembly} or {framework} and they will be replaced in the output result file. This is useful if you use multitargeting in your test projects. See example below.

# Assume we have this directory structure of tests
> tree
.
├── SampleTests
│   ├── UnitTest1.cs
│   └── SampleTests.csproj

> cd SampleTests
> dotnet test --logger:"xunit;LogFileName=mytestfile.xml"

# Note the output file
> tree
.
├── SampleTests
│   ├── TestResults
│   │   ├── mytestfile.xml    # test result file
│   ├── UnitTest1.cs
│   └── SampleTests.csproj

# Use assembly name or framework token in test results file
> dotnet test --logger:"xunit;LogFileName={assembly}.results.xml"
Results File: /tmp/SampleTests/TestResults/SampleTests.results.xml

> dotnet test --logger:"xunit;LogFileName={assembly}.{framework}.results.xml"
Results File: /tmp/SampleTests/TestResults/SampleTests.NETCoreApp31.results.xml

LogFilePath

Use this option to provide an absolute path for the result file. The parent directory will be created if it doesn't exist.

LogFilePath accepts token expansion. E.g. you can provide {assembly} or {framework} and they will be replaced in the output result file. See example below.

# Assume we have this directory structure of tests
> tree
.
├── SampleTests
│   ├── UnitTest1.cs
│   └── SampleTests.csproj

> cd SampleTests
> dotnet test --logger:"xunit;LogFilePath=/tmp/SampleTests/results/mytestfile.xml"

# Note the output file
> tree
.
├── SampleTests
│   ├── results
│   │   ├── mytestfile.xml    # test result file
│   ├── UnitTest1.cs
│   └── SampleTests.csproj

# Use assembly name or framework token in test results file
> dotnet test --logger:"xunit;LogFilePath=/tmp/SampleTests/results/{assembly}.results.xml"
Results File: /tmp/SampleTests/results/SampleTests.results.xml

> dotnet test --logger:"xunit;LogFilePath=/tmp/SampleTests/results/{assembly}.{framework}.results.xml"
Results File: /tmp/SampleTests/results/SampleTests.NETCoreApp31.results.xml
Clone this wiki locally