This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging.cs
62 lines (51 loc) · 1.59 KB
/
Logging.cs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.IO;
using System.Text;
using System.Xml;
using Tomato.Properties;
namespace Tomato
{
/// <summary>
/// Handles activity log file creation.
/// </summary>
public class Logging
{
public static string FilePath
{
get
{
return Environment.CurrentDirectory + "/log.xml";
}
}
public static bool FileExists
{
get
{
return File.Exists(FilePath);
}
}
public static void WriteActivityLog(string activity, DateTime time)
{
if (!FileExists)
{
CreateFileFromTemplate();
}
XmlDocument document = new XmlDocument();
document.Load(FilePath);
XmlElement activityElement = document.CreateElement("Activity");
XmlElement descriptionElement = document.CreateElement("Description");
descriptionElement.InnerText = activity;
XmlElement timeElement = document.CreateElement("StartTime");
timeElement.InnerText = time.ToString();
activityElement.AppendChild(timeElement);
activityElement.AppendChild(descriptionElement);
XmlNode rootElement = document.GetElementsByTagName("log")[0];
rootElement.AppendChild(activityElement);
document.Save(FilePath);
}
public static void CreateFileFromTemplate()
{
File.WriteAllText(FilePath, Resources.logging_template_xml, Encoding.UTF8);
}
}
}