I know this is waay late, but I was able to get a file logger working with the following code. It can be configured to do rolling logs or just purge the log when it gets to a certain size and start filling it again.
The idea is that there is only one instance of the logger (singleton) to avoid problems with different instances trying to write to the same location concurrently. It's supposed to be thread-safe, but I haven't really tested that aspect of it yet.
public class FileLogger : ILogger { private static FileLogger _instance; private static object lockObject = new Object(); #region Constructors private FileLogger(string filePath, long maxFileSize, bool isRolling) { this.FilePath = filePath; this.MaxFileSize = maxFileSize; this.IsRolling = isRolling; } #endregion #region Public Properties public static FileLogger Instance { get { if (FileLogger._instance == null) throw new Exception("File logger has not been instantiated."); return FileLogger._instance; } } public static bool IsInstantiated { get; private set; } public string FilePath { get; private set; } public long MaxFileSize { get; private set; } public bool IsRolling { get; private set; } #endregion #region ILogger Members public void Log(Severity severity, string message) { if (this.FilePath == null || this.FilePath.Trim().Length == 0) throw new Exception("Must specify file path for logging."); lock (FileLogger.lockObject) { if (File.Exists(this.FilePath)) { var fileInfo = new FileInfo(this.FilePath); if (this.MaxFileSize != -1 && fileInfo.Length > this.MaxFileSize) { if (!this.IsRolling) File.Delete(this.FilePath); else this.rollFile(); } } using (var fileStream = new FileStream(this.FilePath, FileMode.Append)) using (var streamWriter = new StreamWriter(fileStream)) streamWriter.WriteLine(DateTime.Now.ToString() + " - " + severity.ToString().ToUpper() + " - " + message); } } #endregion #region Public Methods public static FileLogger Instantiate( string filePath, long maxFileSize = -1, bool isRolling = false) { if (FileLogger.IsInstantiated) throw new Exception("File logger has already been instantiated."); lock (FileLogger.lockObject) { FileLogger._instance = new FileLogger(filePath, maxFileSize, isRolling); FileLogger.IsInstantiated = true; } return FileLogger._instance; } #endregion #region Private Methods private void rollFile() { if (!File.Exists(this.FilePath)) throw new Exception( "Failed to roll log file. '" + this.FilePath + "' does not exist."); int fileExtensionIndex = this.FilePath.LastIndexOf('.'); string rolledFilePath = this.FilePath.Substring(0, fileExtensionIndex) + "_" + Guid.NewGuid().ToString() + this.FilePath.Substring(fileExtensionIndex, this.FilePath.Length - fileExtensionIndex); File.Move(this.FilePath, rolledFilePath); } #endregion }