<PackageReference Include="NUnit" Version="4.3.0" />

InternalTraceWriter

A trace listener that writes to a separate file per domain and process using it.
using System.IO; using System.Runtime.CompilerServices; using System.Text; namespace NUnit.Framework.Internal { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class InternalTraceWriter : TextWriter { private readonly TextWriter _writer; private readonly object _myLock = new object(); public override Encoding Encoding => _writer.Encoding; public InternalTraceWriter(string logPath) { _writer = new StreamWriter(new FileStream(logPath, FileMode.Append, FileAccess.Write, FileShare.Write)) { AutoFlush = true }; } public InternalTraceWriter(TextWriter writer) { _writer = writer; } public override void Write(char value) { lock (_myLock) { _writer.Write(value); } } [System.Runtime.CompilerServices.NullableContext(2)] public override void Write(string value) { lock (_myLock) { _writer.Write(value); } } [System.Runtime.CompilerServices.NullableContext(2)] public override void WriteLine(string value) { lock (_myLock) { _writer.WriteLine(value); } } protected override void Dispose(bool disposing) { if (disposing && _writer != null) { _writer.Flush(); _writer.Dispose(); } base.Dispose(disposing); } public override void Flush() { _writer.Flush(); } } }