Friday, July 5, 2013

really simple logging

using System.IO;
using Whatever.Core;
namespace Whatever.Infrastructure
{
   public class Logging : ILogging
   {
      public void Write(IClock clock, string message)
      {
         string path = @"C:\log.txt";
         if (!File.Exists(path))
         {
            using (StreamWriter streamWriter = File.CreateText(path))
            {
               streamWriter.WriteLine("beginning log at " + clock.CurrentTime());
            }
         }
         using (StreamWriter streamWriter = File.AppendText(path))
         {
            streamWriter.WriteLine("log at " + clock.CurrentTime() + ": " + message);
         }
      }
   }
}

No comments:

Post a Comment