Code: Select all
HostApplicationBuilder builder = Host.CreateApplicationBuilder();
builder.Logging.ClearProviders();
builder.Logging.AddCustomLogger(logFilePath);
using (IHost host = builder.Build())
{
host.RunAsync();
var hostLogger = host.Services.GetRequiredService();
hostLogger.LogDebug("debug");
}
string readLog = File.ReadAllText(logFilePath, Encoding.Unicode);
Console.WriteLine(readLog);
Code: Select all
_logFileStream = new FileStream(logFilePath, new FileStreamOptions()
{
Access = FileAccess.Write,
Mode = FileMode.Append,
Share = FileShare.ReadWrite
});
Code: Select all
public override void Dispose()
{
if (_logFileStream != null)
{
_logFileStream.Close();
_logFileStream.Dispose();
}
}
Ich habe versucht, dem Host einen Shutdown/Warten hinzuzufügen:
Code: Select all
host.StopAsync();
host.WaitForShutdown();
Wie kann ich diesen IHost dazu bringen, meine Datei loszulassen?
Mobile version