本文整理汇总了C#中LoggingEvent.GetExceptionString方法的典型用法代码示例。如果您正苦于以下问题:C# LoggingEvent.GetExceptionString方法的具体用法?C# LoggingEvent.GetExceptionString怎么用?C# LoggingEvent.GetExceptionString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoggingEvent
的用法示例。
在下文中一共展示了LoggingEvent.GetExceptionString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Append
protected override void Append(LoggingEvent loggingEvent)
{
Entry entry = new Entry
{
id = TimedUuid.GenerateTimeBasedGuid(DateTime.Now),
app_name = AppName,
host_ip = _ipAddress,
host_name = _hostname,
logger_name = loggingEvent.LoggerName,
level = loggingEvent.Level.ToString(),
message = loggingEvent.RenderedMessage,
app_start_time = LoggingEvent.StartTime,
thread_name = loggingEvent.ThreadName,
log_timestamp = loggingEvent.TimeStamp,
throwable_str_rep = loggingEvent.GetExceptionString()
};
LocationInfo locInfo = loggingEvent.LocationInformation;
if (locInfo != null)
{
entry.class_name = locInfo.ClassName;
entry.file_name = locInfo.FileName;
entry.line_number = int.Parse(locInfo.LineNumber);
entry.method_name = locInfo.MethodName;
}
_insert.Execute(entry).AsFuture();
}
示例2: RenderLoggingEvent
/// <summary>
/// Renders the <see cref="LoggingEvent"/> to a string.
/// </summary>
/// <param name="loggingEvent">The event to render.</param>
/// <param name="writer">The TextWriter to write the formatted event to</param>
/// <remarks>
/// <para>
/// Helper method to render a <see cref="LoggingEvent"/> to
/// a string. This appender must have a <see cref="Layout"/>
/// set to render the <paramref name="loggingEvent"/> to
/// a string.
/// </para>
/// <para>If there is exception data in the logging event and
/// the layout does not process the exception, this method
/// will append the exception text to the rendered string.
/// </para>
/// <para>
/// Use this method in preference to <see cref="M:RenderLoggingEvent(LoggingEvent)"/>
/// where possible. If, however, the caller needs to render the event
/// to a string then <see cref="M:RenderLoggingEvent(LoggingEvent)"/> does
/// provide an efficient mechanism for doing so.
/// </para>
/// </remarks>
protected void RenderLoggingEvent(TextWriter writer, LoggingEvent loggingEvent)
{
if (m_layout == null)
{
throw new InvalidOperationException("A layout must be set");
}
if (m_layout.IgnoresException)
{
string exceptionStr = loggingEvent.GetExceptionString();
if (exceptionStr != null && exceptionStr.Length > 0)
{
// render the event and the exception
m_layout.Format(writer, loggingEvent);
writer.WriteLine(exceptionStr);
}
else
{
// there is no exception to render
m_layout.Format(writer, loggingEvent);
}
}
else
{
// The layout will render the exception
m_layout.Format(writer, loggingEvent);
}
}
示例3: FormatXml
/// <summary>
/// Does the actual writing of the XML.
/// </summary>
/// <param name="writer">The writer to use to output the event to.</param>
/// <param name="loggingEvent">The event to write.</param>
/// <remarks>
/// <para>
/// Override the base class <see cref="XmlLayoutBase.FormatXml"/> method
/// to write the <see cref="LoggingEvent"/> to the <see cref="XmlWriter"/>.
/// </para>
/// </remarks>
override protected void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
writer.WriteStartElement(m_elmEvent);
writer.WriteAttributeString(ATTR_LOGGER, loggingEvent.LoggerName);
writer.WriteAttributeString(ATTR_TIMESTAMP, XmlConvert.ToString(loggingEvent.TimeStamp, XmlDateTimeSerializationMode.Local));
writer.WriteAttributeString(ATTR_LEVEL, loggingEvent.Level.DisplayName);
writer.WriteAttributeString(ATTR_THREAD, loggingEvent.ThreadName);
if (loggingEvent.Domain != null && loggingEvent.Domain.Length > 0)
{
writer.WriteAttributeString(ATTR_DOMAIN, loggingEvent.Domain);
}
if (loggingEvent.Identity != null && loggingEvent.Identity.Length > 0)
{
writer.WriteAttributeString(ATTR_IDENTITY, loggingEvent.Identity);
}
if (loggingEvent.UserName != null && loggingEvent.UserName.Length > 0)
{
writer.WriteAttributeString(ATTR_USERNAME, loggingEvent.UserName);
}
// Append the message text
writer.WriteStartElement(m_elmMessage);
if (!this.Base64EncodeMessage)
{
Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, this.InvalidCharReplacement);
}
else
{
byte[] messageBytes = Encoding.UTF8.GetBytes(loggingEvent.RenderedMessage);
string base64Message = Convert.ToBase64String(messageBytes, 0, messageBytes.Length);
Transform.WriteEscapedXmlString(writer, base64Message,this.InvalidCharReplacement);
}
writer.WriteEndElement();
PropertiesDictionary properties = loggingEvent.GetProperties();
// Append the properties text
if (properties.Count > 0)
{
writer.WriteStartElement(m_elmProperties);
foreach(System.Collections.DictionaryEntry entry in properties)
{
writer.WriteStartElement(m_elmData);
writer.WriteAttributeString(ATTR_NAME, Transform.MaskXmlInvalidCharacters((string)entry.Key,this.InvalidCharReplacement));
// Use an ObjectRenderer to convert the object to a string
string valueStr =null;
if (!this.Base64EncodeProperties)
{
valueStr = Transform.MaskXmlInvalidCharacters(loggingEvent.Repository.RendererMap.FindAndRender(entry.Value),this.InvalidCharReplacement);
}
else
{
byte[] propertyValueBytes = Encoding.UTF8.GetBytes(loggingEvent.Repository.RendererMap.FindAndRender(entry.Value));
valueStr = Convert.ToBase64String(propertyValueBytes, 0, propertyValueBytes.Length);
}
writer.WriteAttributeString(ATTR_VALUE, valueStr);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
string exceptionStr = loggingEvent.GetExceptionString();
if (exceptionStr != null && exceptionStr.Length > 0)
{
// Append the stack trace line
writer.WriteStartElement(m_elmException);
Transform.WriteEscapedXmlString(writer, exceptionStr,this.InvalidCharReplacement);
writer.WriteEndElement();
}
if (LocationInfo)
{
LocationInfo locationInfo = loggingEvent.LocationInformation;
writer.WriteStartElement(m_elmLocation);
writer.WriteAttributeString(ATTR_CLASS, locationInfo.ClassName);
writer.WriteAttributeString(ATTR_METHOD, locationInfo.MethodName);
writer.WriteAttributeString(ATTR_FILE, locationInfo.FileName);
writer.WriteAttributeString(ATTR_LINE, locationInfo.LineNumber);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
示例4: Format
/// <summary>
/// Gets the exception text from the logging event
/// </summary>
/// <param name="writer">The TextWriter to write the formatted event to</param>
/// <param name="loggingEvent">the event being logged</param>
/// <remarks>
/// <para>
/// Write the exception string to the <see cref="TextWriter"/>.
/// The exception string is retrieved from <see cref="M:LoggingEvent.GetExceptionString()"/>.
/// </para>
/// </remarks>
override public void Format(TextWriter writer, LoggingEvent loggingEvent)
{
if (loggingEvent == null)
{
throw new ArgumentNullException("loggingEvent");
}
writer.Write(loggingEvent.GetExceptionString());
}
示例5: FormatXml
//.........这里部分代码省略.........
// translate appdomain name
if (loggingEvent.LookupProperty("log4japp") == null &&
loggingEvent.Domain != null &&
loggingEvent.Domain.Length > 0)
{
loggingEvent.GetProperties()["log4japp"] = loggingEvent.Domain;
}
// translate identity name
if (loggingEvent.Identity != null &&
loggingEvent.Identity.Length > 0 &&
loggingEvent.LookupProperty(LoggingEvent.IdentityProperty) == null)
{
loggingEvent.GetProperties()[LoggingEvent.IdentityProperty] = loggingEvent.Identity;
}
// translate user name
if (loggingEvent.UserName != null &&
loggingEvent.UserName.Length > 0 &&
loggingEvent.LookupProperty(LoggingEvent.UserNameProperty) == null)
{
loggingEvent.GetProperties()[LoggingEvent.UserNameProperty] = loggingEvent.UserName;
}
// Write the start element
writer.WriteStartElement("log4j:event");
writer.WriteAttributeString("logger", loggingEvent.LoggerName);
// Calculate the timestamp as the number of milliseconds since january 1970
//
// We must convert the TimeStamp to UTC before performing any mathematical
// operations. This allows use to take into account discontinuities
// caused by daylight savings time transitions.
TimeSpan timeSince1970 = loggingEvent.TimeStamp.ToUniversalTime() - s_date1970;
writer.WriteAttributeString("timestamp", XmlConvert.ToString((long)timeSince1970.TotalMilliseconds));
writer.WriteAttributeString("level", loggingEvent.Level.DisplayName);
writer.WriteAttributeString("thread", loggingEvent.ThreadName);
// Append the message text
writer.WriteStartElement("log4j:message");
Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage,this.InvalidCharReplacement);
writer.WriteEndElement();
object ndcObj = loggingEvent.LookupProperty("NDC");
if (ndcObj != null)
{
string valueStr = loggingEvent.Repository.RendererMap.FindAndRender(ndcObj);
if (valueStr != null && valueStr.Length > 0)
{
// Append the NDC text
writer.WriteStartElement("log4j:NDC");
Transform.WriteEscapedXmlString(writer, valueStr,this.InvalidCharReplacement);
writer.WriteEndElement();
}
}
// Append the properties text
PropertiesDictionary properties = loggingEvent.GetProperties();
if (properties.Count > 0)
{
writer.WriteStartElement("log4j:properties");
foreach(System.Collections.DictionaryEntry entry in properties)
{
writer.WriteStartElement("log4j:data");
writer.WriteAttributeString("name", (string)entry.Key);
// Use an ObjectRenderer to convert the object to a string
string valueStr = loggingEvent.Repository.RendererMap.FindAndRender(entry.Value);
writer.WriteAttributeString("value", valueStr);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
string exceptionStr = loggingEvent.GetExceptionString();
if (exceptionStr != null && exceptionStr.Length > 0)
{
// Append the stack trace line
writer.WriteStartElement("log4j:throwable");
Transform.WriteEscapedXmlString(writer, exceptionStr,this.InvalidCharReplacement);
writer.WriteEndElement();
}
if (LocationInfo)
{
LocationInfo locationInfo = loggingEvent.LocationInformation;
writer.WriteStartElement("log4j:locationInfo");
writer.WriteAttributeString("class", locationInfo.ClassName);
writer.WriteAttributeString("method", locationInfo.MethodName);
writer.WriteAttributeString("file", locationInfo.FileName);
writer.WriteAttributeString("line", locationInfo.LineNumber);
writer.WriteEndElement();
}
writer.WriteEndElement();
}