add permanent independent tracelog
This commit is contained in:
@@ -5,6 +5,7 @@ using MareSynchronos.Services.Mediator;
|
|||||||
using MareSynchronos.Utils;
|
using MareSynchronos.Utils;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
|
||||||
namespace MareSynchronos.FileCache;
|
namespace MareSynchronos.FileCache;
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
private long _currentFileProgress = 0;
|
private long _currentFileProgress = 0;
|
||||||
private CancellationTokenSource _scanCancellationTokenSource = new();
|
private CancellationTokenSource _scanCancellationTokenSource = new();
|
||||||
private readonly CancellationTokenSource _periodicCalculationTokenSource = new();
|
private readonly CancellationTokenSource _periodicCalculationTokenSource = new();
|
||||||
private readonly string[] _allowedExtensions = [".mdl", ".tex", ".mtrl", ".tmb", ".pap", ".avfx", ".atex", ".sklb", ".eid", ".phyb", ".scd", ".skp", ".shpk"];
|
public static readonly IImmutableList<string> AllowedFileExtensions = [".mdl", ".tex", ".mtrl", ".tmb", ".pap", ".avfx", ".atex", ".sklb", ".eid", ".phyb", ".scd", ".skp", ".shpk"];
|
||||||
|
|
||||||
public CacheMonitor(ILogger<CacheMonitor> logger, IpcManager ipcManager, MareConfigService configService,
|
public CacheMonitor(ILogger<CacheMonitor> logger, IpcManager ipcManager, MareConfigService configService,
|
||||||
FileCacheManager fileDbManager, MareMediator mediator, PerformanceCollectorService performanceCollector, DalamudUtilService dalamudUtil,
|
FileCacheManager fileDbManager, MareMediator mediator, PerformanceCollectorService performanceCollector, DalamudUtilService dalamudUtil,
|
||||||
@@ -151,7 +152,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
Logger.LogTrace("Mare FSW: FileChanged: {change} => {path}", e.ChangeType, e.FullPath);
|
Logger.LogTrace("Mare FSW: FileChanged: {change} => {path}", e.ChangeType, e.FullPath);
|
||||||
|
|
||||||
if (!_allowedExtensions.Any(ext => e.FullPath.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) return;
|
if (!AllowedFileExtensions.Any(ext => e.FullPath.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) return;
|
||||||
|
|
||||||
lock (_watcherChanges)
|
lock (_watcherChanges)
|
||||||
{
|
{
|
||||||
@@ -195,7 +196,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
private void Fs_Changed(object sender, FileSystemEventArgs e)
|
private void Fs_Changed(object sender, FileSystemEventArgs e)
|
||||||
{
|
{
|
||||||
if (Directory.Exists(e.FullPath)) return;
|
if (Directory.Exists(e.FullPath)) return;
|
||||||
if (!_allowedExtensions.Any(ext => e.FullPath.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) return;
|
if (!AllowedFileExtensions.Any(ext => e.FullPath.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) return;
|
||||||
|
|
||||||
if (e.ChangeType is not (WatcherChangeTypes.Changed or WatcherChangeTypes.Deleted or WatcherChangeTypes.Created))
|
if (e.ChangeType is not (WatcherChangeTypes.Changed or WatcherChangeTypes.Deleted or WatcherChangeTypes.Created))
|
||||||
return;
|
return;
|
||||||
@@ -219,7 +220,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
foreach (var file in directoryFiles)
|
foreach (var file in directoryFiles)
|
||||||
{
|
{
|
||||||
if (!_allowedExtensions.Any(ext => file.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) continue;
|
if (!AllowedFileExtensions.Any(ext => file.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) continue;
|
||||||
var oldPath = file.Replace(e.FullPath, e.OldFullPath, StringComparison.OrdinalIgnoreCase);
|
var oldPath = file.Replace(e.FullPath, e.OldFullPath, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
_watcherChanges.Remove(oldPath);
|
_watcherChanges.Remove(oldPath);
|
||||||
@@ -231,7 +232,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!_allowedExtensions.Any(ext => e.FullPath.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) return;
|
if (!AllowedFileExtensions.Any(ext => e.FullPath.EndsWith(ext, StringComparison.OrdinalIgnoreCase))) return;
|
||||||
|
|
||||||
lock (_watcherChanges)
|
lock (_watcherChanges)
|
||||||
{
|
{
|
||||||
@@ -497,7 +498,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
[
|
[
|
||||||
.. Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
|
.. Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories)
|
||||||
.AsParallel()
|
.AsParallel()
|
||||||
.Where(f => _allowedExtensions.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase))
|
.Where(f => AllowedFileExtensions.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase))
|
||||||
&& !f.Contains(@"\bg\", StringComparison.OrdinalIgnoreCase)
|
&& !f.Contains(@"\bg\", StringComparison.OrdinalIgnoreCase)
|
||||||
&& !f.Contains(@"\bgcommon\", StringComparison.OrdinalIgnoreCase)
|
&& !f.Contains(@"\bgcommon\", StringComparison.OrdinalIgnoreCase)
|
||||||
&& !f.Contains(@"\ui\", StringComparison.OrdinalIgnoreCase)),
|
&& !f.Contains(@"\ui\", StringComparison.OrdinalIgnoreCase)),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using MareSynchronos.MareConfiguration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NReco.Logging.File;
|
||||||
|
|
||||||
namespace MareSynchronos.Interop;
|
namespace MareSynchronos.Interop;
|
||||||
|
|
||||||
@@ -14,7 +15,6 @@ public static class DalamudLoggingProviderExtensions
|
|||||||
|
|
||||||
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, DalamudLoggingProvider>
|
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, DalamudLoggingProvider>
|
||||||
(b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog, hasModifiedGameFiles)));
|
(b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog, hasModifiedGameFiles)));
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="8.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="8.0.7" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||||
<PackageReference Include="Glamourer.Api" Version="2.1.0" />
|
<PackageReference Include="Glamourer.Api" Version="2.1.0" />
|
||||||
|
<PackageReference Include="NReco.Logging.File" Version="1.2.1" />
|
||||||
<PackageReference Include="Penumbra.Api" Version="5.2.0" />
|
<PackageReference Include="Penumbra.Api" Version="5.2.0" />
|
||||||
<PackageReference Include="Penumbra.String" Version="1.0.4" />
|
<PackageReference Include="Penumbra.String" Version="1.0.4" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace MareSynchronos.PlayerData.Factories;
|
|||||||
|
|
||||||
public class PlayerDataFactory
|
public class PlayerDataFactory
|
||||||
{
|
{
|
||||||
private static readonly string[] _allowedExtensionsForGamePaths = [".mdl", ".tex", ".mtrl", ".tmb", ".pap", ".avfx", ".atex", ".sklb", ".eid", ".phyb", ".scd", ".skp", ".shpk"];
|
|
||||||
private readonly DalamudUtilService _dalamudUtil;
|
private readonly DalamudUtilService _dalamudUtil;
|
||||||
private readonly FileCacheManager _fileCacheManager;
|
private readonly FileCacheManager _fileCacheManager;
|
||||||
private readonly IpcManager _ipcManager;
|
private readonly IpcManager _ipcManager;
|
||||||
@@ -156,7 +155,7 @@ public class PlayerDataFactory
|
|||||||
previousData.FileReplacements[objectKind] =
|
previousData.FileReplacements[objectKind] =
|
||||||
new HashSet<FileReplacement>(resolvedPaths.Select(c => new FileReplacement([.. c.Value], c.Key)), FileReplacementComparer.Instance)
|
new HashSet<FileReplacement>(resolvedPaths.Select(c => new FileReplacement([.. c.Value], c.Key)), FileReplacementComparer.Instance)
|
||||||
.Where(p => p.HasFileReplacement).ToHashSet();
|
.Where(p => p.HasFileReplacement).ToHashSet();
|
||||||
previousData.FileReplacements[objectKind].RemoveWhere(c => c.GamePaths.Any(g => !_allowedExtensionsForGamePaths.Any(e => g.EndsWith(e, StringComparison.OrdinalIgnoreCase))));
|
previousData.FileReplacements[objectKind].RemoveWhere(c => c.GamePaths.Any(g => !CacheMonitor.AllowedFileExtensions.Any(e => g.EndsWith(e, StringComparison.OrdinalIgnoreCase))));
|
||||||
|
|
||||||
_logger.LogDebug("== Static Replacements ==");
|
_logger.LogDebug("== Static Replacements ==");
|
||||||
foreach (var replacement in previousData.FileReplacements[objectKind].Where(i => i.HasFileReplacement).OrderBy(i => i.GamePaths.First(), StringComparer.OrdinalIgnoreCase))
|
foreach (var replacement in previousData.FileReplacements[objectKind].Where(i => i.HasFileReplacement).OrderBy(i => i.GamePaths.First(), StringComparer.OrdinalIgnoreCase))
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ using MareSynchronos.WebAPI.SignalR;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NReco.Logging.File;
|
||||||
|
|
||||||
namespace MareSynchronos;
|
namespace MareSynchronos;
|
||||||
|
|
||||||
@@ -37,12 +38,32 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager, INotificationManager notificationManager,
|
IGameGui gameGui, IDtrBar dtrBar, IPluginLog pluginLog, ITargetManager targetManager, INotificationManager notificationManager,
|
||||||
ITextureProvider textureProvider, IContextMenu contextMenu)
|
ITextureProvider textureProvider, IContextMenu contextMenu)
|
||||||
{
|
{
|
||||||
|
if (!Directory.Exists(pluginInterface.ConfigDirectory.FullName))
|
||||||
|
Directory.CreateDirectory(pluginInterface.ConfigDirectory.FullName);
|
||||||
|
var traceDir = Path.Join(pluginInterface.ConfigDirectory.FullName, "tracelog");
|
||||||
|
if (!Directory.Exists(traceDir))
|
||||||
|
Directory.CreateDirectory(traceDir);
|
||||||
|
|
||||||
|
foreach (var file in Directory.EnumerateFiles(traceDir)
|
||||||
|
.Select(f => new FileInfo(f))
|
||||||
|
.OrderByDescending(f => f.LastWriteTimeUtc).Skip(9))
|
||||||
|
{
|
||||||
|
file.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
_host = new HostBuilder()
|
_host = new HostBuilder()
|
||||||
.UseContentRoot(pluginInterface.ConfigDirectory.FullName)
|
.UseContentRoot(pluginInterface.ConfigDirectory.FullName)
|
||||||
.ConfigureLogging(lb =>
|
.ConfigureLogging(lb =>
|
||||||
{
|
{
|
||||||
lb.ClearProviders();
|
lb.ClearProviders();
|
||||||
lb.AddDalamudLogging(pluginLog, gameData.HasModifiedGameDataFiles);
|
lb.AddDalamudLogging(pluginLog, gameData.HasModifiedGameDataFiles);
|
||||||
|
lb.AddFile(Path.Combine(traceDir, $"mare-trace-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.log"), (opt) =>
|
||||||
|
{
|
||||||
|
opt.Append = true;
|
||||||
|
opt.RollingFilesConvention = FileLoggerOptions.FileRollingConvention.Ascending;
|
||||||
|
opt.MinLevel = LogLevel.Trace;
|
||||||
|
opt.FileSizeLimitBytes = 50 * 1024 * 1024;
|
||||||
|
});
|
||||||
lb.SetMinimumLevel(LogLevel.Trace);
|
lb.SetMinimumLevel(LogLevel.Trace);
|
||||||
})
|
})
|
||||||
.ConfigureServices(collection =>
|
.ConfigureServices(collection =>
|
||||||
|
|||||||
Reference in New Issue
Block a user