-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
48 lines (44 loc) · 1.67 KB
/
Logger.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
using System;
using System.IO;
namespace HungerGamesTelegram
{
public static class Logger
{
static string basePath = @"C:\Users\akvitberg\OneDrive\Hunger Games";
public static void Log(Actor actor, string message)
{
var line = DateTime.Now.ToString("HH:mm:ss") + ": " + message.Replace("\n", "\n ");
if (actor is TelegramPlayer player)
{
try
{
EnsureFolder(Path.Combine(basePath, "log", player.Game.Name));
File.AppendAllText(Path.Combine(basePath, "log", player.Game.Name, "eventlog.txt"), player.Name + " - " + line + "\n");
File.AppendAllText(Path.Combine(basePath, "log", player.Game.Name, player.Name + ".txt"), line + "\n");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
private static void EnsureFolder(string combine)
{
Directory.CreateDirectory(combine);
}
public static void Log(Game game, string message)
{
var line = DateTime.Now.ToString("HH:mm:ss") + ": " + message.Replace("\n", "\n ");
try
{
EnsureFolder(Path.Combine(basePath, "log", game.Name));
File.AppendAllText(Path.Combine(basePath, "log", game.Name, "gamelog.txt"), line + "\n");
File.AppendAllText(Path.Combine(basePath, "log", game.Name, "eventlog.txt"), line + "\n");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}