title: xUnit and log on the same file while testing
body: <p>I just updated to xUnit 2.1.
  I'm using this method via a lot of tests running in parallels from differents assemblies to log to the same file with a certain name.
  The problem is I can't manage concurrency (even using <a href="https://msdn.microsoft.com/it-it/library/system.io.textwriter.synchronized(v=vs.110).aspx" rel="nofollow noreferrer">TextWriter.Synchronized</a>), every time I run my tests, different tests says:</p>
  
  <p>The error is:</p>
  
  <pre><code>Message: System.IO.IOException : The process cannot access the file 'C:\LOGS\myFileName-20170510.txt' because it is being used by another process.
  </code></pre>
  
  <p>My method is:</p>
  
  <pre><code>private static void WriteToLogFile(string fileName, string strMessage)
          {
              DateTime utcNow = DateTime.UtcNow;
              lock (fileName)
              {
                  using (StreamWriter w = File.AppendText(fileName + utcNow.Year + utcNow.Month.ToString("00") + utcNow.Day.ToString("00") + ".txt"))
                  {
                      w.WriteLine("{0};{1};{2}", DateTime.UtcNow, SecurityHelper.GetPrincipalName(), strMessage);
                      w.Flush();
                      w.Close();
                  }
              }
          }
  </code></pre>
  
  <p>I tried even (but this doesn't helped):</p>
  
  <pre><code>private static void WriteToLogFile(string fileName, string strMessage)
  {
      DateTime utcNow = DateTime.UtcNow;
      lock (fileName)
      {
          using (StreamWriter w = File.AppendText(fileName + utcNow.Year + utcNow.Month.ToString("00") + utcNow.Day.ToString("00") + ".txt"))
          {
              w.WriteLine("{0};{1};{2}", DateTime.UtcNow, SecurityHelper.GetPrincipalName(), strMessage);
              w.Flush();
              w.Close();
          }
      }
  }
  
  private static readonly ConcurrentDictionary&lt;string, object&gt; Tokens = new ConcurrentDictionary&lt;string, object&gt;();
  
  private static object GetToken(string fileName)
  {
      if (!Tokens.ContainsKey(fileName))
          Tokens.TryAdd(fileName, new object());
      return Tokens[fileName];
  }
  </code></pre>
  
  <p>This is due to some strange behaviour of xUnit?
  Thanks in advance.</p>