本文整理汇总了C#中Error.AddObject方法的典型用法代码示例。如果您正苦于以下问题:C# Error.AddObject方法的具体用法?C# Error.AddObject怎么用?C# Error.AddObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Error
的用法示例。
在下文中一共展示了Error.AddObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToErrorModel
/// <summary>
/// Sets the properties from an exception.
/// </summary>
/// <param name="exception">The exception to populate properties from.</param>
/// <param name="log">The log implementation used for diagnostic information.</param>
public static Error ToErrorModel(this Exception exception, IExceptionlessLog log) {
Type type = exception.GetType();
var error = new Error {
Message = exception.GetMessage(),
Modules = GetLoadedModules(log),
Type = type.FullName
};
error.PopulateStackTrace(error, exception);
try {
PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
error.Code = info.GetValue(exception, null).ToString();
} catch (Exception) {}
if (exception.TargetSite != null) {
error.TargetMethod = new Method();
error.TargetMethod.PopulateMethod(error, exception.TargetSite);
}
// TODO: Test adding non-serializable objects to ExtendedData and see what happens
try {
Dictionary<string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
try {
return p.GetValue(exception, null);
} catch {}
return null;
});
extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)) {
error.AddObject(new ExtendedDataInfo {
Data = extraProperties,
Name = Error.KnownDataKeys.ExtraProperties,
IgnoreSerializationErrors = true,
MaxDepthToSerialize = 5
});
}
} catch {}
if (exception.InnerException != null)
error.Inner = exception.InnerException.ToErrorModel(log);
return error;
}
示例2: ToErrorModelInternal
private static Error ToErrorModelInternal(Exception exception, ExceptionlessClient client, bool isInner = false) {
var log = client.Configuration.Resolver.GetLog();
Type type = exception.GetType();
var error = new Error {
Message = exception.GetMessage(),
Type = type.FullName
};
if (!isInner)
error.Modules = GetLoadedModules(log);
error.PopulateStackTrace(error, exception, log);
try {
PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
error.Code = info.GetValue(exception, null).ToString();
} catch (Exception) { }
try {
if (exception.TargetSite != null) {
error.TargetMethod = new Method();
error.TargetMethod.PopulateMethod(error, exception.TargetSite);
}
} catch (Exception ex) {
log.Error(typeof(ExceptionlessClient), ex, "Error populating TargetMethod: " + ex.Message);
}
try {
var exclusions = _exceptionExclusions.Union(client.Configuration.DataExclusions);
var extraProperties = type.GetPublicProperties().Where(p => !p.Name.AnyWildcardMatches(exclusions, true)).ToDictionary(p => p.Name, p => {
try {
return p.GetValue(exception, null);
} catch { }
return null;
});
extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)) {
error.AddObject(new ExtendedDataInfo {
Data = extraProperties,
Name = Error.KnownDataKeys.ExtraProperties,
IgnoreSerializationErrors = true,
MaxDepthToSerialize = 5
}, client);
}
} catch { }
if (exception.InnerException != null)
error.Inner = ToErrorModelInternal(exception.InnerException, client, true);
return error;
}
示例3: ToErrorModel
/// <summary>
/// Sets the properties from an exception.
/// </summary>
/// <param name="exception">The exception to populate properties from.</param>
/// <param name="log">The log implementation used for diagnostic information.</param>
public static Error ToErrorModel(this Exception exception
#if EMBEDDED
, IExceptionlessLog log = null
#endif
) {
if (exception == null)
throw new ArgumentNullException("exception");
#if EMBEDDED
if (log == null)
log = new NullExceptionlessLog();
#endif
Type type = exception.GetType();
var error = new Error {
Message = exception.GetMessage(),
#if EMBEDDED
Modules = GetLoadedModules(log),
#else
Modules = GetLoadedModules(),
#endif
Type = type.FullName
};
error.PopulateStackTrace(error, exception);
#if !SILVERLIGHT
try {
PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
if (info != null)
error.Code = info.GetValue(exception, null).ToString();
} catch (Exception) {}
#endif
if (exception.TargetSite != null) {
error.TargetMethod = new Method();
error.TargetMethod.PopulateMethod(error, exception.TargetSite);
}
// TODO: Test adding non-serializable objects to ExtendedData and see what happens
try {
Dictionary<string, object> extraProperties = type.GetPublicProperties().Where(p => !_exceptionExclusions.Contains(p.Name)).ToDictionary(p => p.Name, p => {
try {
return p.GetValue(exception, null);
} catch {}
return null;
});
extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
if (extraProperties.Count > 0 && !error.ExtendedData.ContainsKey(ExtendedDataDictionary.EXCEPTION_INFO_KEY)) {
error.AddObject(new ExtendedDataInfo {
Data = extraProperties,
Name = ExtendedDataDictionary.EXCEPTION_INFO_KEY,
IgnoreSerializationErrors = true,
MaxDepthToSerialize = 5
});
}
} catch {}
if (exception.InnerException != null)
error.Inner = exception.InnerException.ToErrorModel();
return error;
}