mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
LoggingSettings.LogToFile
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive.Subjects;
|
using System.Reactive.Subjects;
|
||||||
@ -12,6 +12,12 @@ using Path = Alphaleonis.Win32.Filesystem.Path;
|
|||||||
|
|
||||||
namespace Wabbajack.Common
|
namespace Wabbajack.Common
|
||||||
{
|
{
|
||||||
|
public static class LoggingSettings
|
||||||
|
{
|
||||||
|
// False by default, so that library users do not have to swap it
|
||||||
|
public static bool LogToFile = false;
|
||||||
|
}
|
||||||
|
|
||||||
public static partial class Utils
|
public static partial class Utils
|
||||||
{
|
{
|
||||||
public static AbsolutePath LogFile { get; private set; }
|
public static AbsolutePath LogFile { get; private set; }
|
||||||
@ -25,14 +31,16 @@ namespace Wabbajack.Common
|
|||||||
public static IObservable<IStatusMessage> LogMessages => LoggerSubj;
|
public static IObservable<IStatusMessage> LogMessages => LoggerSubj;
|
||||||
|
|
||||||
private static async Task InitalizeLogging()
|
private static async Task InitalizeLogging()
|
||||||
|
{
|
||||||
|
_startTime = DateTime.Now;
|
||||||
|
|
||||||
|
if (LoggingSettings.LogToFile)
|
||||||
{
|
{
|
||||||
LogFolder = Consts.LogsFolder;
|
LogFolder = Consts.LogsFolder;
|
||||||
LogFile = Consts.LogFile;
|
LogFile = Consts.LogFile;
|
||||||
Consts.LocalAppDataPath.CreateDirectory();
|
Consts.LocalAppDataPath.CreateDirectory();
|
||||||
Consts.LogsFolder.CreateDirectory();
|
Consts.LogsFolder.CreateDirectory();
|
||||||
|
|
||||||
_startTime = DateTime.Now;
|
|
||||||
|
|
||||||
if (LogFile.Exists)
|
if (LogFile.Exists)
|
||||||
{
|
{
|
||||||
var newPath = Consts.LogsFolder.Combine(Consts.EntryPoint.FileNameWithoutExtension + LogFile.LastModified.ToString(" yyyy-MM-dd HH_mm_ss") + ".log");
|
var newPath = Consts.LogsFolder.Combine(Consts.EntryPoint.FileNameWithoutExtension + LogFile.LastModified.ToString(" yyyy-MM-dd HH_mm_ss") + ".log");
|
||||||
@ -70,6 +78,10 @@ namespace Wabbajack.Common
|
|||||||
Log($"Deleted {success} log files, failed to delete {failed} logs");
|
Log($"Deleted {success} log files, failed to delete {failed} logs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void Log(string msg)
|
public static void Log(string msg)
|
||||||
{
|
{
|
||||||
Log(new GenericInfo(msg));
|
Log(new GenericInfo(msg));
|
||||||
@ -112,7 +124,7 @@ namespace Wabbajack.Common
|
|||||||
|
|
||||||
public static void LogStraightToFile(string msg)
|
public static void LogStraightToFile(string msg)
|
||||||
{
|
{
|
||||||
if (LogFile == default) return;
|
if (!LoggingSettings.LogToFile || LogFile == default) return;
|
||||||
lock (_logLock)
|
lock (_logLock)
|
||||||
{
|
{
|
||||||
File.AppendAllText(LogFile.ToString(), $"{(DateTime.Now - _startTime).TotalSeconds:0.##} - {msg}\r\n");
|
File.AppendAllText(LogFile.ToString(), $"{(DateTime.Now - _startTime).TotalSeconds:0.##} - {msg}\r\n");
|
||||||
|
@ -12,6 +12,7 @@ namespace Wabbajack.Server
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
LoggingSettings.LogToFile = true;
|
||||||
Consts.IsServer = true;
|
Consts.IsServer = true;
|
||||||
bool testMode = args.Contains("TESTMODE");
|
bool testMode = args.Contains("TESTMODE");
|
||||||
CreateHostBuilder(args, testMode).Build().Run();
|
CreateHostBuilder(args, testMode).Build().Run();
|
||||||
|
@ -11,6 +11,8 @@ namespace Wabbajack
|
|||||||
{
|
{
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
|
LoggingSettings.LogToFile = true;
|
||||||
|
|
||||||
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
|
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
|
||||||
if (CLIArguments.Help)
|
if (CLIArguments.Help)
|
||||||
CLIOld.DisplayHelpText();
|
CLIOld.DisplayHelpText();
|
||||||
|
Reference in New Issue
Block a user