title: How to Log service response in a single file
body: <p>I have a WCF service. I have this operation that logs any request that comes in to the the service. The problem I have here is that it logs each request in a separate file. How can I log everything in a single file separating each log with a single line? </p>
  
  <p>I wanted to log it in one file for a performance reason. </p>
  
  <pre><code>      public byte sendMessage(string strMsgId, string strMessage)
          {
          byte result = 1;
          try
          {
              if (strMsgId == "02") 
              {
                  // Logging---------------------------------------------------------------------------------
                  // Build timestamp string
                  var currentDateTime = DateTime.Now;
                  string timeStampString = currentDateTime.ToString("yyyy-MM-dd hhmmssfff");
  
                  // Build filename for Inbound messages, concat timestamp and .txt extension.
                  string debugFileName = "C:\\Inboundmessage" + " " + timeStampString + ".txt";
                  var inboundMessageLog = new StreamWriter(debugFileName, false, System.Text.Encoding.Default);
                  // Write to the file:
                  inboundMessageLog.WriteLine(DateTime.Now);
                  inboundMessageLog.WriteLine("Time = {0}", currentDateTime.ToString("yyyy-MM-dd hh:mm:ss:fff tt"));
                  inboundMessageLog.WriteLine("{0}{1}{2}", "Inbound Message:", Environment.NewLine, strMessage.Substring(1016, 26));
                  inboundMessageLog.Close();
  
                  // -------------------------------------------------------------------------------------------
                  result = 0;
              }
  
          }
          catch
          {
              //Failed
              result = 1;
          }
          return result;  
  </code></pre>