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