Код: Выделить всё
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);
Код: Выделить всё
_logFileStream = new FileStream(logFilePath, new FileStreamOptions()
{
Access = FileAccess.Write,
Mode = FileMode.Append,
Share = FileShare.ReadWrite
});
Код: Выделить всё
public override void Dispose()
{
if (_logFileStream != null)
{
_logFileStream.Close();
_logFileStream.Dispose();
}
}
Я пробовал добавить на хост завершение работы/ожидание:
Код: Выделить всё
host.StopAsync();
host.WaitForShutdown();
Как мне заставить этот IHost освободить мой файл?>
Подробнее здесь: https://stackoverflow.com/questions/798 ... er-dispose
Мобильная версия