本文整理汇总了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,
};
}