/// <summary> /// Formats the given message as configured and Appends it to the given StringBuilder /// </summary> /// <param name="lm">Gives the LogMessage instance to format and Append</param> /// <param name="ostr">Gives the StringBuilder instance to Append the formatted message into.</param> public void FormatLogMessageToStringBuilder(LogMessage lm, System.Text.StringBuilder ostr) { bool firstItem = (ostr.Length == 0); if (date) { TabIfNeeded(ostr, ref firstItem); ostr.Append(lm.GetFormattedDateTime()); } if (qpc) { TabIfNeeded(ostr, ref firstItem); ostr.Append((lm.EmittedQpcTime.Time % 1000.0).ToString("000.000000")); } if (level) { TabIfNeeded(ostr, ref firstItem); ostr.Append(ConvertToFixedWidthString(lm.MesgType)); } if (source) { TabIfNeeded(ostr, ref firstItem); ostr.Append(lm.LoggerName); } { TabIfNeeded(ostr, ref firstItem); ostr.Append(lm.Mesg); } if (IncludeKeywords) { ostr.Append(tabStr); ostr.Append(lm.Keywords); } if (data) { ostr.Append(tabStr); ostr.Append("["); ostr.Append(base64UrlCoder.Encode(lm.Data)); ostr.Append("]"); } if (IncludeThreadInfo) { ostr.Append(tabStr); ostr.Append(FormatThreadInfo(lm)); } if (fAndL && lm.SourceStackFrame != null) { { ostr.Append(tabStr); ostr.Append(lm.SourceStackFrame.GetFileName()); } { ostr.Append(tabStr); ostr.Append(lm.SourceStackFrame.GetFileLineNumber().ToString()); } } { ostr.Append(endLStr); } }
/// <summary> /// Formats the given message as configured and incrementally Writes it to the given StreamWriter /// </summary> /// <param name="lm">Gives the LogMessage instance to format and Write</param> /// <param name="os">Gives the StreamWriter instance to Write the formatted message to.</param> public void FormatLogMessageToOstream(LogMessage lm, System.IO.StreamWriter os) { if (!os.BaseStream.CanWrite) return; bool firstItem = true; if (date) { TabIfNeeded(os, ref firstItem); os.Write(lm.GetFormattedDateTime()); } if (qpc) { TabIfNeeded(os, ref firstItem); os.Write((lm.EmittedQpcTime.Time % 1000.0).ToString("000.000000")); } if (level) { TabIfNeeded(os, ref firstItem); os.Write(ConvertToFixedWidthString(lm.MesgType)); } if (source) { TabIfNeeded(os, ref firstItem); os.Write(lm.LoggerName); } { TabIfNeeded(os, ref firstItem); os.Write(lm.Mesg); } if (IncludeKeywords) { os.Write(tabStr); os.Write(lm.Keywords); } if (data) { os.Write(tabStr); os.Write("[{0}]", base64UrlCoder.Encode(lm.Data)); } if (IncludeThreadInfo) { os.Write(tabStr); os.Write(FormatThreadInfo(lm)); } if (fAndL && lm.SourceStackFrame != null) { { os.Write(tabStr); os.Write(lm.SourceStackFrame.GetFileName()); } { os.Write(tabStr); os.Write(lm.SourceStackFrame.GetFileLineNumber().ToString()); } } { os.Write(endLStr); } }