78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using BS.SharedLauncher.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BS.SharedLauncher.Information
|
|
{
|
|
public static class GenericTextLogger
|
|
{
|
|
private static bool _started;
|
|
|
|
private static string _LogFileName;
|
|
private static string _LogFilePath;
|
|
private static string _Session;
|
|
|
|
static GenericTextLogger()
|
|
{
|
|
_started = false;
|
|
}
|
|
|
|
public static void Init(string folder)
|
|
{
|
|
_LogFileName = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
|
_LogFilePath = folder.Combine(_LogFileName);
|
|
|
|
folder.CreateFolder();
|
|
|
|
_Session = new Random().Next(1, 10000).ToString("0000");
|
|
|
|
_started = true;
|
|
|
|
PostWithout("");
|
|
}
|
|
|
|
public static void PostWithout(string str)
|
|
{
|
|
File.AppendAllText(_LogFilePath, str + "\n");
|
|
}
|
|
public static void Post(string message)
|
|
{
|
|
if (!_started)
|
|
return;
|
|
|
|
var log = $"[#{_Session} {DateTime.Now.ToString("HH:mm:ss")}]: {message}";
|
|
|
|
PostWithout(log);
|
|
}
|
|
public static void PostArrow(string message)
|
|
{
|
|
Post("--> " + message);
|
|
}
|
|
public static void PostLine()
|
|
{
|
|
Post("-----------------------------------");
|
|
}
|
|
public static void PostEmpty()
|
|
{
|
|
PostWithout("");
|
|
}
|
|
public static void PostImportantInfo(string info)
|
|
{
|
|
PostLine();
|
|
Post($">>> {info} <<<");
|
|
PostLine();
|
|
}
|
|
public static void PostException(Exception e) => PostError(e.ToString());
|
|
public static void PostError(string error)
|
|
{
|
|
PostLine();
|
|
Post("!!!Error!!! " + error);
|
|
PostLine();
|
|
}
|
|
}
|
|
}
|