title: c# parallel processing , log each thread to a separate file
body: <p>I have a parallel ForEach that calls another method to so some processing, in the other method I use Enterprise Logging. 
  Currently the log all goes to one file, I would like to have each thread create its own log file at least each thread that meets a certain criteria to have it own log file. is this possible with Enterprise logging.
  I am thinking I can define multiple switches in the configuration file and then use those switches in the logging, will that work</p>
  
  <p>current Code</p>
  
  <pre><code>                Parallel.ForEach(
                  listOfAccounts,
                  new ParallelOptions { MaxDegreeOfParallelism = 10},
                  accountId =&gt;
                  {
                      AccountProcess(accountId);
                  });
  </code></pre>
  
  <p>This is the method called:</p>
  
  <pre><code>    private void AccountProcess(int accountId)
      {
          string msgPrefix = MethodBase.GetCurrentMethod().DeclaringType.Name + "." + MethodBase.GetCurrentMethod().Name;
  
          _logWriter.WriteLog(msgPrefix, string.Format(" Starting AccountProcess method with accountId: {0} on threadID: {1}", accountId, Thread.CurrentThread.ManagedThreadId),
              "Information", 0, 0, TraceEventType.Information);
  
          try
          {
              _processor = new AccountProcessor(_logWriter);
              bool result = _processor.AccountProcess(accountId);
              _logWriter.WriteLog(msgPrefix, string.Format(" Account Process result: {0} on threadID: {1}", result.ToString(), Thread.CurrentThread.ManagedThreadId),
                  "Information", 0, 0, TraceEventType.Information);
          }
          catch(Exception ex)
          {
              _logWriter.WriteLog(msgPrefix,
                  string.Format("Error: {0}", ex.Message), "Error", 1, 1, TraceEventType.Error);
              bool rethrow = ExceptionPolicy.HandleException(ex, "Fatal");
              if (rethrow)
              {
                  throw;
              }
          }
          finally
          {
              _processor = null;
          }
          _logWriter.WriteLog(msgPrefix, string.Format(" Completed AccountProcess method with accountId: {0} on threadID: {1}", accountId, Thread.CurrentThread.ManagedThreadId),
              "Information", 0, 0, TraceEventType.Information);
      }
  </code></pre>
  
  <p>In the AccountProcess Method I want to log each thread to a new file.
  Do I need to create a new instance of LogWriter for each thread rather than use the singleton of Enterprise logging V6.
  The _logWriter is wrapper to the Singleton instance of LogWriter in version 6 of Enterprise logging OR do need to use multiple switches.
  I have three type of threads (each thread has a property based on the accountID. so based on the particular type I can use particular switch eg.</p>
  
  <pre><code>  &lt;add switchValue="Type1" name="Information"&gt;
      &lt;listeners&gt;
        &lt;add name="Informational Listener"/&gt;
      &lt;/listeners&gt;
    &lt;/add&gt;
  
    &lt;add switchValue="Type2" name="Information"&gt;
      &lt;listeners&gt;
        &lt;add name="Informational Listener"/&gt;
      &lt;/listeners&gt;
    &lt;/add&gt;
  
    &lt;add switchValue="Type3" name="Information"&gt;
      &lt;listeners&gt;
        &lt;add name="Informational Listener"/&gt;
      &lt;/listeners&gt;
    &lt;/add&gt;
  </code></pre>
  
  <p>would this approach work?</p>