mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-07 03:17:16 +08:00
log to hutao
This commit is contained in:
parent
62dcd1a5c7
commit
41be466d30
@ -67,6 +67,7 @@ public partial class App : Application
|
||||
{
|
||||
loggerConfiguration.WriteTo.RichTextBox(richTextBox, LogEventLevel.Information, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}");
|
||||
}
|
||||
loggerConfiguration.WriteTo.Sink(new HutaoNamedPipeLogEventSink(), LogEventLevel.Information);
|
||||
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
services.AddLogging(c => c.AddSerilog());
|
||||
|
@ -92,6 +92,10 @@ internal sealed partial class BGINamedPipe : IDisposable
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case (PipePacketType.SessionTermination, _):
|
||||
serverStream.Disconnect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO.Pipes;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace BetterGenshinImpact.Hutao;
|
||||
|
||||
@ -40,6 +37,18 @@ internal sealed partial class HutaoNamedPipe : IDisposable
|
||||
get => isSupported.Value;
|
||||
}
|
||||
|
||||
public bool TryRedirectLog(string log)
|
||||
{
|
||||
if (!IsSupported)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(log);
|
||||
clientStream.Write(buffer, 0, buffer.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
clientStream.Dispose();
|
||||
|
37
BetterGenshinImpact/Hutao/HutaoNamedPipeLogEventSink.cs
Normal file
37
BetterGenshinImpact/Hutao/HutaoNamedPipeLogEventSink.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using Serilog.Formatting.Display;
|
||||
using System.IO;
|
||||
|
||||
namespace BetterGenshinImpact.Hutao;
|
||||
|
||||
internal sealed class HutaoNamedPipeLogEventSink : ILogEventSink
|
||||
{
|
||||
private readonly MessageTemplateTextFormatter textFormatter = new("[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}");
|
||||
|
||||
private readonly MemoryStream buffer;
|
||||
private readonly TextWriter writer;
|
||||
private readonly TextReader reader;
|
||||
|
||||
private HutaoNamedPipe? namedPipe;
|
||||
|
||||
public HutaoNamedPipeLogEventSink()
|
||||
{
|
||||
buffer = new();
|
||||
writer = new StreamWriter(buffer);
|
||||
reader = new StreamReader(buffer);
|
||||
}
|
||||
|
||||
private HutaoNamedPipe NamedPipe
|
||||
{
|
||||
get => namedPipe ??= App.GetService<HutaoNamedPipe>()!;
|
||||
}
|
||||
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
textFormatter.Format(logEvent, writer);
|
||||
buffer.Position = 0;
|
||||
NamedPipe.TryRedirectLog(reader.ReadToEnd());
|
||||
buffer.SetLength(0);
|
||||
}
|
||||
}
|
@ -395,8 +395,8 @@
|
||||
<Run Text="启动参数" />
|
||||
<ui:HyperlinkButton Grid.Row="1"
|
||||
Margin="0,0,0,0"
|
||||
Command="{Binding OpenGameCommandLineDocumentCommand}"
|
||||
Padding="0"
|
||||
Command="{Binding OpenGameCommandLineDocumentCommand}"
|
||||
Cursor="Hand">
|
||||
<ui:HyperlinkButton.Content>
|
||||
<TextBlock FontSize="11" Text="打开文档" />
|
||||
|
Loading…
Reference in New Issue
Block a user