protected void SendMessage(ProtocolMessage message) { if (Trace.HasFlag(TraceLevel.Responses) && message.type == "response") { Console.Error.WriteLine(string.Format(" R: {0}", JsonConvert.SerializeObject(message))); } if (Trace.HasFlag(TraceLevel.Requests) && message.type == "request") { Console.Error.WriteLine(string.Format(" Q: {0}", JsonConvert.SerializeObject(message))); } if (Trace.HasFlag(TraceLevel.Events) && message.type == "event") { Event e = (Event)message; Console.Error.WriteLine(string.Format("E {0}: {1}", e.eventType, JsonConvert.SerializeObject(e.body))); } var data = ConvertToBytes(message); try { _outputStream.Write(data, 0, data.Length); _outputStream.Flush(); } catch (Exception) { // ignore } }
public void Trace(TraceLevels level, string format, params object[] args) { lock (_traceLock) { if (TraceLevel.HasFlag(level)) { _traceWriter.WriteLine( DateTime.UtcNow.ToString("HH:mm:ss.fffffff", CultureInfo.InvariantCulture) + " - " + (ConnectionId ?? "null") + " - " + format, args); } } }