This repository has been archived by the owner on May 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Log.cs
62 lines (48 loc) · 2.11 KB
/
Log.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.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Threading;
using System.Windows;
namespace OS_Game_Launcher
{
class Log
{
private static string sLogFormat;
private static string sErrorTime;
private static string sPathNameError = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "OS Game-Launcher Logs", "errors.log");
private static string sPathNameWarning = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "OS Game-Launcher Logs", "warnings.log");
private static void GenerateTimestamps()
{
//sLogFormat used to create log files format :
// dd/mm/yyyy hh:mm:ss AM/PM ==> Log Message
sLogFormat = DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString() + " :: ";
//this variable used to create log filename format "
//for example filename : ErrorLogYYYYMMDD
string sYear = DateTime.Now.Year.ToString();
string sMonth = DateTime.Now.Month.ToString();
string sDay = DateTime.Now.Day.ToString();
sErrorTime = sYear + sMonth + sDay;
}
public static void Fatal(string sErrMsg)
{
GenerateTimestamps();
Utils.CreateDirectoryIfNotExists(Path.GetDirectoryName(sPathNameError));
StreamWriter sw = new StreamWriter(sPathNameError, true);
sw.WriteLine(sLogFormat + sErrMsg + "\n\n");
sw.Flush();
sw.Close();
}
public static void Warning(string sWarnMsg)
{
GenerateTimestamps();
Utils.CreateDirectoryIfNotExists(Path.GetDirectoryName(sPathNameError));
StreamWriter sw = new StreamWriter(sPathNameWarning, true);
sw.WriteLine(sLogFormat + sWarnMsg + "\n\n");
sw.Flush();
sw.Close();
}
}
}