C# dotnet core中winforms中的ConsoleLogger提供程序
我正在用dotnetcore编写一个tcp通信管理解决方案。 此库正在使用Microsoft.Extensions.Logging包进行日志记录 现在,我想将winforms应用程序作为实用工具工具包添加到解决方案中 在winforms控件中接收日志输出的最佳方法是什么。目前,我正试图通过从Console.OpenStandardOutput()读取流来使用ConsoleLogger提供程序 使用当前的方法,我在预期的日志输出中缺少了一些行C# dotnet core中winforms中的ConsoleLogger提供程序,c#,winforms,logging,.net-core,C#,Winforms,Logging,.net Core,我正在用dotnetcore编写一个tcp通信管理解决方案。 此库正在使用Microsoft.Extensions.Logging包进行日志记录 现在,我想将winforms应用程序作为实用工具工具包添加到解决方案中 在winforms控件中接收日志输出的最佳方法是什么。目前,我正试图通过从Console.OpenStandardOutput()读取流来使用ConsoleLogger提供程序 使用当前的方法,我在预期的日志输出中缺少了一些行 private static void MainFor
private static void MainForm_Load(object sender, EventArgs e)
{
var mainForm = sender as Form1;
var uiContext = SynchronizationContext.Current;
var s = new MemoryStream();
var w = new StreamWriter(s, Encoding.UTF7) { AutoFlush = true };
var reader = new StreamReader(s, Encoding.UTF7);
Console.SetIn(reader);
Console.SetOut(w);
Task.Run(() =>
{
while (true)
{
var newLine = reader.ReadLine();
if (newLine != null)
{
uiContext.Send(_ => { mainForm.WriteConsoleLine(newLine); }, null);
}
}
});
}
我曾考虑编写自己的MainformLoggerProvider,但我对winforms的了解有限,我希望采用一种更为开箱即用的方法