简体   繁体   English

Websocket清晰的日志文件输出

[英]Websocket sharp log file output

I'm using Websocket sharp ( https://github.com/sta/websocket-sharp ) for a console program, how do I output all debug/trace information that are displayed on the console to a text file? 我正在将Websocket sharp( https://github.com/sta/websocket-sharp )用于控制台程序,如何将控制台上显示的所有调试/跟踪信息输出到文本文件?

For example: 例如:

using (var ws = new WebSocket(WebAddr))
            {

                ws.Log.Level = LogLevel.Debug;
                ws.OnOpen += (ss, ee) =>
                {
                  System.IO.File.WriteAllText(@"C:\log.txt", ws.Log.ToString());

                };

But the output for this is "WebSocketSharp.Logger". 但是,此输出是“ WebSocketSharp.Logger”。

I would expecting something like this: 我期望这样的事情:

Screenshot 屏幕截图

Set the property File : 设置属性File

using (var ws = new WebSocket(WebAddr))
{
    ws.Log.Level = LogLevel.Debug;

    ws.Log.File = @"C:\log.txt";
}

You will need to provide alot more information (which data?, how often? etc.) but you can use the System.IO.File methods for easy writing to a file; 您将需要提供更多的信息(哪些数据,多少频率等),但是您可以使用System.IO.File方法轻松写入文件;

// To create a new file
System.IO.File.WriteAllText(@"FileNameToWriteTo.txt", aString);
System.IO.File.WriteAllLines(@"FileNameToWriteTo.txt", listOfStrings);

// To add to the end of an existing file
System.IO.File.AppendAllText(@"FileNameToWriteTo.txt", aString);
System.IO.File.AppendAllLines(@"FileNameToWriteTo.txt", listOfStrings);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM