title: 51Degrees.mobi Logging Slows Down ASP.NET MVC
body: <p>The following line in <code>51Degrees.mobi.config</code> adds 2-3 seconds of loading time to each of my ASP.NET MVC 4 project's controller actions:</p>
  
  <pre><code>&lt;fiftyOne&gt;
      &lt;log logFile="~/bin/App_Data/51Log.txt" logLevel="Info" /&gt;
      ...
  &lt;/fiftyOne
  </code></pre>
  
  <p>The same thing happens for ASP.NET MVC 3. If I remove the <code>&lt;log&gt;</code> section, pages load almost instantly. I'm using the binary device database for detection like so:</p>
  
  <pre><code>&lt;detection binaryFilePath="~/App_Data/51Degrees.mobi-Lite-2012.01.05.dat" /&gt;
  </code></pre>
  
  <p>Setting the <code>logLevel</code> to <code>Debug</code> causes the following exception:</p>
  
  <pre><code>`Storage scopes cannot be created when _AppStart is executing.`
  </code></pre>
  
  <p>Why does this cause such a drastic slowdown? Is it a symptom of a deeper problem?</p>
  
  <p>Could there be an incompatibility with StructureMap for dependency injection?</p>
  
  <hr>
  
  <p><strong>Update:</strong> Thanks to @James Rosewell, I figured out why the logging slowed down my application. It's related to the <em><code>logFile</code> path</em>. Everytime 51Degrees writes to the 51Log.txt file in the <code>~/bin</code> directory, it causes IIS to recycle the pool and reload all the modules. Changing the log path to <code>~/App_Data</code> solved the problem.</p>