Reputation: 15
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:
Upvotes: 0
Views: 3078
Reputation: 15941
Set the property File
:
using (var ws = new WebSocket(WebAddr))
{
ws.Log.Level = LogLevel.Debug;
ws.Log.File = @"C:\log.txt";
}
Upvotes: 4
Reputation: 6417
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);
Upvotes: 0