-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCommandLoggerLogger.cs
41 lines (38 loc) · 1.18 KB
/
CommandLoggerLogger.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
using System.IO;
using Logger = Rocket.Core.Logging.Logger;
namespace coolpuppy24.commandlogger
{
/// <summary>
/// Using this like an adapter for StreamWriter.
/// </summary>
public sealed class CommandLoggerLogger
{
private string m_filepath;
private FileMode m_filemode;
private FileAccess m_fileaccess;
public CommandLoggerLogger()
{
this.m_filepath = CommandLoggerCore.Instance.Directory + @"\CoolPuppy24.WisserTg.CommandLogger.log";
this.m_filemode = FileMode.Append;
this.m_fileaccess = FileAccess.Write;
}
public CommandLoggerLogger(string FilePath) : this()
{
this.m_filepath = CommandLoggerCore.Instance.Directory + FilePath;
}
public void Log(string Message)
{
if (CommandLoggerCore.Instance.Configuration.Instance.LogToFile)
{
if (!File.Exists(this.m_filepath))
this.m_filemode = FileMode.CreateNew;
using (StreamWriter sw = new StreamWriter(new FileStream(this.m_filepath, this.m_filemode, this.m_fileaccess)))
sw.WriteLine(Message);
if (this.m_filemode == FileMode.CreateNew)
this.m_filemode = FileMode.Append;
}
if (CommandLoggerCore.Instance.Configuration.Instance.LogToConsole)
Logger.Log(Message);
}
}
}