update logging and add pl splash as the main one
All checks were successful
Build / Build Launcher (push) Successful in 2m31s
All checks were successful
Build / Build Launcher (push) Successful in 2m31s
This commit is contained in:
@@ -1,77 +1,37 @@
|
||||
using VRage.Utils;
|
||||
using System.Runtime.CompilerServices;
|
||||
using NLog;
|
||||
using NLog.Layouts;
|
||||
using NLog.Targets;
|
||||
using NLog.Targets.Wrappers;
|
||||
|
||||
namespace PluginLoader;
|
||||
|
||||
public static class LogFile
|
||||
{
|
||||
private const string fileName = "loader.log";
|
||||
private static StreamWriter writer;
|
||||
private const string FileName = "loader.log";
|
||||
private const string LoggerName = "PluginLoader";
|
||||
|
||||
public static readonly Logger Log = LogManager.GetLogger(LoggerName);
|
||||
|
||||
public static void Init(string mainPath)
|
||||
{
|
||||
var file = Path.Combine(mainPath, fileName);
|
||||
try
|
||||
RuntimeHelpers.RunClassConstructor(
|
||||
Type.GetType("GameAnalyticsSDK.Net.Logging.GALogger, GameAnalytics.Mono", true)!.TypeHandle);
|
||||
|
||||
var target = new AsyncTargetWrapper(new FileTarget
|
||||
{
|
||||
writer = File.CreateText(file);
|
||||
}
|
||||
catch
|
||||
Name = "pluginLog",
|
||||
Layout = Layout.FromString("${longdate:universaltime=true} ${level} ${message:withexception=true}"),
|
||||
FileName = Layout.FromString(Path.Combine(mainPath, FileName)),
|
||||
FileNameKind = FilePathKind.Absolute,
|
||||
EnableFileDelete = true,
|
||||
DeleteOldFileOnStartup = true,
|
||||
});
|
||||
LogManager.Configuration.AddTarget(target);
|
||||
LogManager.Configuration.LoggingRules.Insert(0, new(LoggerName, LogLevel.Trace, target)
|
||||
{
|
||||
writer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specifed text to the log file.
|
||||
/// WARNING: Not thread safe!
|
||||
/// </summary>
|
||||
public static void WriteLine(string text, bool gameLog = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
writer?.WriteLine($"{DateTime.UtcNow:O} {text}");
|
||||
if (gameLog)
|
||||
WriteGameLog(text);
|
||||
writer?.Flush();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specifed text to the game log file.
|
||||
/// This function is thread safe.
|
||||
/// </summary>
|
||||
public static void WriteGameLog(string text)
|
||||
{
|
||||
MyLog.Default.WriteLine($"[PluginLoader] {text}");
|
||||
}
|
||||
|
||||
public static void WriteTrace(string text, bool gameLog = true)
|
||||
{
|
||||
#if DEBUG
|
||||
writer?.WriteLine($"{DateTime.UtcNow:O} {text}");
|
||||
if (gameLog)
|
||||
WriteGameLog($"[PluginLoader] {text}");
|
||||
writer?.Flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Dispose()
|
||||
{
|
||||
if (writer == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
writer.Flush();
|
||||
writer.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
writer = null;
|
||||
FinalMinLevel = LogLevel.Info
|
||||
});
|
||||
LogManager.ReconfigExistingLoggers();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user