SerilogEnricher
Some checks failed
FModel QA Builder / build (push) Has been cancelled

This commit is contained in:
LongerWarrior 2025-01-30 22:40:11 +02:00
parent 32334a079f
commit a704612544
6 changed files with 92 additions and 18 deletions

@ -1 +1 @@
Subproject commit e45f85472248e38b35fae893fa1bf69851aa90eb
Subproject commit 94dbeb7cd3232b6719120219ae7d2a63968e9036

View File

@ -104,15 +104,20 @@ public partial class App
Directory.CreateDirectory(Path.Combine(UserSettings.Default.OutputDirectory, "Logs"));
Directory.CreateDirectory(Path.Combine(UserSettings.Default.OutputDirectory, ".data"));
const string template = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {Enriched}: {Message:lj}{NewLine}{Exception}";
Log.Logger = new LoggerConfiguration()
#if DEBUG
Log.Logger = new LoggerConfiguration().WriteTo.Console(theme: AnsiConsoleTheme.Literate).WriteTo.File(
Path.Combine(UserSettings.Default.OutputDirectory, "Logs", $"FModel-Debug-Log-{DateTime.Now:yyyy-MM-dd}.txt"),
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [FModel] [{Level:u3}] {Message:lj}{NewLine}{Exception}").CreateLogger();
.Enrich.With<SourceEnricher>()
.MinimumLevel.Verbose()
.WriteTo.Console(outputTemplate: template, theme: AnsiConsoleTheme.Literate)
.WriteTo.File(outputTemplate: template,
path: Path.Combine(UserSettings.Default.OutputDirectory, "Logs", $"FModel-Debug-Log-{DateTime.Now:yyyy-MM-dd}.txt"))
#else
Log.Logger = new LoggerConfiguration().WriteTo.Console(theme: AnsiConsoleTheme.Literate).WriteTo.File(
Path.Combine(UserSettings.Default.OutputDirectory, "Logs", $"FModel-Log-{DateTime.Now:yyyy-MM-dd}.txt"),
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [FModel] [{Level:u3}] {Message:lj}{NewLine}{Exception}").CreateLogger();
.Enrich.With<CallerEnricher>()
.WriteTo.File(outputTemplate: template,
path: Path.Combine(UserSettings.Default.OutputDirectory, "Logs", $"FModel-Log-{DateTime.Now:yyyy-MM-dd}.txt"))
#endif
.CreateLogger();
Log.Information("Version {Version} ({CommitId})", Constants.APP_VERSION, Constants.APP_COMMIT_ID);
Log.Information("{OS}", GetOperatingSystemProductName());
@ -183,4 +188,4 @@ public partial class App
return rk.GetValue(name, null) as string;
return string.Empty;
}
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.Diagnostics;
using System.Reflection;
using Serilog.Core;
using Serilog.Events;
namespace FModel.Framework;
public abstract class SerilogEnricher : ILogEventEnricher
{
public abstract void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory);
protected bool TryGetCaller(out MethodBase method)
{
method = null;
var serilogAssembly = typeof(Serilog.Log).Assembly;
var stack = new StackTrace(3);
foreach (var frame in stack.GetFrames())
{
var m = frame.GetMethod();
if (m?.DeclaringType is null) continue;
if (m.DeclaringType.Assembly != serilogAssembly)
{
method = m;
break;
}
}
return method != null;
}
}
public class SourceEnricher : SerilogEnricher
{
public override void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var source = "N/A";
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceContext))
{
source = sourceContext.ToString()[1..^1];
}
else if (TryGetCaller(out var method))
{
source = method.DeclaringType?.Namespace;
}
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Enriched", source.Split('.')[0]));
}
}
public class CallerEnricher : SerilogEnricher
{
public override void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (TryGetCaller(out var method))
{
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Enriched", $"{method.DeclaringType?.FullName}.{method.Name}"));
}
}
}

View File

@ -85,10 +85,10 @@ public partial class MainWindow
#if DEBUG
// await _threadWorkerView.Begin(cancellationToken =>
// _applicationView.CUE4Parse.Extract(cancellationToken,
// "FortniteGame/Content/Athena/Apollo/Maps/UI/Apollo_Terrain_Minimap.uasset"));
// "MyProject/Content/FirstPerson/Meshes/FirstPersonProjectileMesh.uasset"));
// await _threadWorkerView.Begin(cancellationToken =>
// _applicationView.CUE4Parse.Extract(cancellationToken,
// "FortniteGame/Content/Environments/Helios/Props/GlacierHotel/GlacierHotel_Globe_A/Meshes/SM_GlacierHotel_Globe_A.uasset"));
// "RED/Content/Chara/ABA/Costume01/Animation/Charaselect/body/stand_body01.uasset"));
#endif
}
@ -208,7 +208,7 @@ public partial class MainWindow
await _threadWorkerView.Begin(cancellationToken => { _applicationView.CUE4Parse.TextureFolder(cancellationToken, folder); });
FLogger.Append(ELog.Information, () =>
{
FLogger.Text("Successfully saved ", Constants.WHITE);
FLogger.Text("Successfully saved textures from ", Constants.WHITE);
FLogger.Link(folder.PathAtThisPoint, UserSettings.Default.TextureDirectory, true);
});
}
@ -219,6 +219,11 @@ public partial class MainWindow
if (AssetsFolderName.SelectedItem is TreeItem folder)
{
await _threadWorkerView.Begin(cancellationToken => { _applicationView.CUE4Parse.ModelFolder(cancellationToken, folder); });
FLogger.Append(ELog.Information, () =>
{
FLogger.Text("Successfully saved models from ", Constants.WHITE);
FLogger.Link(folder.PathAtThisPoint, UserSettings.Default.ModelDirectory, true);
});
}
}
@ -227,6 +232,11 @@ public partial class MainWindow
if (AssetsFolderName.SelectedItem is TreeItem folder)
{
await _threadWorkerView.Begin(cancellationToken => { _applicationView.CUE4Parse.AnimationFolder(cancellationToken, folder); });
FLogger.Append(ELog.Information, () =>
{
FLogger.Text("Successfully saved animations from ", Constants.WHITE);
FLogger.Link(folder.PathAtThisPoint, UserSettings.Default.ModelDirectory, true);
});
}
}

View File

@ -22,7 +22,7 @@ namespace FModel.Services
private readonly Assets _staticAssets = new()
{
LargeImageKey = "official_logo", SmallImageKey = "verified", SmallImageText = $"v{Constants.APP_VERSION}"
LargeImageKey = "official_logo", SmallImageKey = "verified", SmallImageText = $"v{Constants.APP_VERSION} ({Constants.APP_SHORT_COMMIT_ID})"
};
private readonly Button[] _buttons =

View File

@ -912,9 +912,7 @@ public class CUE4ParseViewModel : ViewModel
SnooperViewer.Run();
return true;
}
case UAnimSequence when isNone && ModelIsWaitingAnimation:
case UAnimMontage when isNone && ModelIsWaitingAnimation:
case UAnimComposite when isNone && ModelIsWaitingAnimation:
case UAnimSequenceBase when isNone && ModelIsWaitingAnimation:
{
SnooperViewer.Renderer.Animate(pointer.Object);
SnooperViewer.Run();
@ -924,9 +922,7 @@ public class CUE4ParseViewModel : ViewModel
case USkeletalMesh when HasFlag(bulk, EBulkType.Meshes):
case USkeleton when UserSettings.Default.SaveSkeletonAsMesh && HasFlag(bulk, EBulkType.Meshes):
// case UMaterialInstance when HasFlag(bulk, EBulkType.Materials): // read the fucking json
case UAnimSequence when HasFlag(bulk, EBulkType.Animations):
case UAnimMontage when HasFlag(bulk, EBulkType.Animations):
case UAnimComposite when HasFlag(bulk, EBulkType.Animations):
case UAnimSequenceBase when HasFlag(bulk, EBulkType.Animations):
{
SaveExport(pointer.Object.Value, updateUi);
return true;