Skip to content

Instantly share code, notes, and snippets.

@brunnurs
Created February 16, 2015 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunnurs/e8400a992eb3a6ef5a77 to your computer and use it in GitHub Desktop.
Save brunnurs/e8400a992eb3a6ef5a77 to your computer and use it in GitHub Desktop.
iOS FileLogger
using System;
using Drallo.Mobile.Lib.Helper;
using System.IO;
using System.Diagnostics;
namespace Drallo.Mobile.LibrarySpecializations.Logging
{
public class TouchFileLogger : ILogger
{
static object locker = new object();
private string logfilePath;
public TouchFileLogger()
{
string timeString = DateTime.Now.ToString("yy_MM_dd__hh_mm_ss");
logfilePath = String.Format("{0}/appNameLog_{1}.txt",Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),timeString);
}
#region ILogger implementation
public void Write(LogLevel level, string tag, string message)
{
string timeString = DateTime.Now.ToString("G");
lock (locker)
{
using (StreamWriter w = File.AppendText(logfilePath))
{
w.WriteLine(timeString + " " + level + " " + message);
}
}
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment