本文整理匯總了C#中System.Exception.GetFriendlyToString方法的典型用法代碼示例。如果您正苦於以下問題:C# Exception.GetFriendlyToString方法的具體用法?C# Exception.GetFriendlyToString怎麽用?C# Exception.GetFriendlyToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Exception
的用法示例。
在下文中一共展示了Exception.GetFriendlyToString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateLoggingEvent
private LoggingEvent CreateLoggingEvent(Level level, string message, string category, object data, Exception exception)
{
LoggingEventData eventData = new LoggingEventData();
eventData.LoggerName = this.Logger.Name;
eventData.Level = level;
eventData.TimeStamp = DateTime.Now;
if (exception != null)
{
if (String.IsNullOrEmpty(message))
{
eventData.Message = data == null ? exception.Message : exception.Message + "\r\n相關數據: " + XMS.Core.Formatter.PlainObjectFormatter.Simplified.Format(data);
eventData.ExceptionString = exception.GetFriendlyStackTrace();
}
else
{
eventData.Message = data == null ? message : message + "\r\n相關數據: " + XMS.Core.Formatter.PlainObjectFormatter.Simplified.Format(data);
eventData.ExceptionString = exception.GetFriendlyToString();
}
}
else
{
eventData.Message = data == null ? message : message + "\r\n相關數據: " + XMS.Core.Formatter.PlainObjectFormatter.Simplified.Format(data);
}
LoggingEvent loggingEvent = new LoggingEvent(ThisDeclaringType, this.Logger.Repository, eventData, FixFlags.None);
// LoggingEvent loggingEvent = new LoggingEvent(ThisDeclaringType, this.Logger.Repository, this.Logger.Name, level, message, exception);
//// 應用相關的信息
//loggingEvent.Properties["RunMode"] = RunContext.Current.RunMode.ToString().ToLower();
//loggingEvent.Properties["AppName"] = Container.ConfigService.AppName;
//loggingEvent.Properties["AppVersion"] = Container.ConfigService.AppVersion;
// 日誌類別
loggingEvent.Properties["Category"] = String.IsNullOrEmpty(category) ? "default" : category;
// 訪問者信息
loggingEvent.Properties["UserIP"] = SecurityContext.Current.UserIP;
loggingEvent.Properties["UserId"] = SecurityContext.Current.User.Identity.UserId;
loggingEvent.Properties["UserName"] = SecurityContext.Current.User.Identity.Name;
return loggingEvent;
}
示例2: GetCustomError
/// <summary>
/// 獲取返回自定義錯誤編碼 的 ReturnValue。
/// </summary>
/// <param name="code">錯誤編碼</param>
/// <param name="ex">異常</param>
/// <param name="message">錯誤信息。</param>
/// <returns>自定義錯誤編碼的 ReturnValue。</returns>
public static ReturnValue GetCustomError(int code, Exception ex, string message = "")
{
if (string.IsNullOrEmpty(message) && ex != null)
{
message = ex.GetFriendlyToString();
}
return new ReturnValue
{
Code = code,
Message = message,
};
}