~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/monomac/samples/macdoc/Logger.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.IO;
 
3
 
 
4
namespace macdoc
 
5
{
 
6
        public static class Logger
 
7
        {
 
8
                static readonly string LogFilePath;
 
9
 
 
10
                static Logger ()
 
11
                {
 
12
                        var baseLogFolder = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "Library", "Logs", "MacDoc");
 
13
                        if (!Directory.Exists (baseLogFolder))
 
14
                                Directory.CreateDirectory (baseLogFolder);
 
15
                        LogFilePath = Path.Combine (baseLogFolder, string.Format ("MacDoc-{0}.log", DateTime.Now.ToString ("s")));
 
16
                }
 
17
 
 
18
                public static void Log (string message)
 
19
                {
 
20
                        Console.WriteLine (message);
 
21
                        File.AppendAllText (LogFilePath, message + Environment.NewLine);
 
22
                }
 
23
 
 
24
                public static void Log (string messageFormat, params object[] args)
 
25
                {
 
26
                        Log (string.Format (messageFormat, args));
 
27
                }
 
28
 
 
29
                public static void LogError (string message, Exception ex)
 
30
                {
 
31
                        Console.WriteLine (message + ": " + ex.Message);
 
32
                        File.AppendAllText (LogFilePath, message + ". " + ex.ToString () + Environment.NewLine);
 
33
                }
 
34
        }
 
35
}
 
36