Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# dotnet core中winforms中的ConsoleLogger提供程序_C#_Winforms_Logging_.net Core - Fatal编程技术网

C# dotnet core中winforms中的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

我正在用dotnetcore编写一个tcp通信管理解决方案。 此库正在使用Microsoft.Extensions.Logging包进行日志记录 现在,我想将winforms应用程序作为实用工具工具包添加到解决方案中

在winforms控件中接收日志输出的最佳方法是什么。目前,我正试图通过从Console.OpenStandardOutput()读取流来使用ConsoleLogger提供程序

使用当前的方法,我在预期的日志输出中缺少了一些行

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的了解有限,我希望采用一种更为开箱即用的方法