本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry.AddErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:C# LogEntry.AddErrorMessage方法的具体用法?C# LogEntry.AddErrorMessage怎么用?C# LogEntry.AddErrorMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry
的用法示例。
在下文中一共展示了LogEntry.AddErrorMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddExceptionInfo
/// <summary>
/// Adds the exception info.
/// </summary>
/// <param name="log">The log entry.</param>
/// <param name="exception">The exception.</param>
/// <returns></returns>
protected virtual void AddExceptionInfo(LogEntry log, Exception exception)
{
if (exception != null && settings.exceptionFormat != null)
{
string errorMessage = settings.exceptionFormat
.Replace("$(exception.message)", exception.Message)
.Replace("$(exception.source)", exception.Source)
.Replace("$(exception.targetsite)", (exception.TargetSite==null)?string.Empty:exception.TargetSite.ToString())
.Replace("$(exception.stacktrace)", exception.StackTrace)
;
// StringBuilder sb = new StringBuilder(128);
// sb.Append("Exception[ ");
// sb.Append("message = ").Append(exception.Message).Append(separator);
// sb.Append("source = ").Append(exception.Source).Append(separator);
// sb.Append("targetsite = ").Append(exception.TargetSite).Append(separator);
// sb.Append("stacktrace = ").Append(exception.StackTrace).Append("]");
// return sb.ToString();
log.AddErrorMessage(errorMessage);
}
}
示例2: Log
public void Log(LoggingData loggingData)
{
var logEntry = new LogEntry();
logEntry.Message = loggingData.Message;
logEntry.AppDomainName = loggingData.Domain;
logEntry.AddErrorMessage(loggingData.ExceptionString);
logEntry.Categories = new string[] { loggingData.LoggerName };
TraceEventType eventType;
if (!s_EventTypeDict.TryGetValue(loggingData.Level, out eventType))
eventType = TraceEventType.Information;
logEntry.Severity = eventType;
logEntry.ManagedThreadName = loggingData.ThreadName;
logEntry.TimeStamp = loggingData.TimeStamp;
m_LogWriter.Write(logEntry);
}