/// <summary> /// Writes a message /// </summary> /// <param name="message">Message to write</param> /// <param name="type">Trace type of this message</param> /// internal void Write(string message, TraceType type) { try { Console.WriteLine($"{DateTime.Now.ToIsoDateTimeString()} {type.GetDisplayName()} {message}"); } catch (Exception ex) { // can't display errors anywhere - try again to write exception try { Console.WriteLine($"Failed to write to console. {ex.GetMessageStackStrings()}"); } catch { // ignore additional exceptions } } }
/// <summary> /// Writes a message /// </summary> /// <param name="message">Message to write</param> /// <param name="type">Trace type</param> internal void Write(string message, TraceType type) { try { if (CheckStream()) { this.StreamWriter?.WriteLine($"{DateTime.Now.ToIsoDateTimeString()} {type.GetDisplayName()} {message}"); // file can be shared if the stream is closed only if (this.Share) { CloseStream(); } } } catch (Exception ex) { try { // can't write into file - bring exception to console Console.WriteLine($"Failed to write trace to file. {ex.GetMessageStackString()}"); } catch { // ignore any additional exceptions } } }