title: Logging in async methods
body: <p>I have this program, that have two async methods, which wants to write something in log at the same time.</p>
  
  <pre><code>class Program
  {
      private const string LOG_FILE = "Log.txt";
      private static object _Lock = new object();
  
      static void Main(string[] args)
      {
          var p = new Program();
  
          new Task(p.Func1).Start();
          new Task(p.Func2).Start();
  
          Console.ReadKey();
      }
  
      private async void Func1()
      {
          for (int i = 0; i &lt; 10; i++)
              this.Log("1");
      }
  
      private async void Func2()
      {
  
          for (int i = 0; i &lt; 10; i++)
              this.Log("2");
      }
  
      private void Log(string msg)
      {
          lock(_Lock)
          {
              File.AppendAllText(LOG_FILE, msg);
          }
      }
  }
  </code></pre>
  
  <p>Output is something like this "11222222222211111111" and could change. Why output is not a "12121212121212121212"? </p>
  
  <p>If I'm correct, then Func2 will wait till Func1 write "1" to log file. Then Func2 will write "2" and Func1 will be waiting.</p>