0

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?

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".

I would expecting something like this:

Screenshot

Rocky Wei
  • 15
  • 1
  • 8

2 Answers2

3

Set the property File:

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

    ws.Log.File = @"C:\log.txt";
}
Alberto
  • 15,626
  • 9
  • 43
  • 56
  • Since this solved your issue, you should click the green checkmark to mark as the answer. It gives points to the answerer – jhhoff02 Jul 10 '17 at 11:36
0

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;

// 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);
Milney
  • 6,253
  • 2
  • 19
  • 33