/// <summary> /// Initializes a new instance of the <see cref="ExceptionlessClient" /> class. /// </summary> internal ExceptionlessClient(IQueueStore store = null, IExceptionlessLog log = null) { _queueTimer = new Timer(OnQueueTimer, null, Timeout.Infinite, Timeout.Infinite); _log = log ?? new NullExceptionlessLog(); try { _configuration = Config.ClientConfiguration.Create(this); Log.FormattedTrace(typeof(ExceptionlessClient), "Configuration Values: ApiKey={0}, EnableSSL={1}, Enabled={2}, ServerUrl={3}", _configuration.ApiKey, _configuration.EnableSSL, _configuration.Enabled, _configuration.ServerUrl); } catch (Exception ex) { Log.FormattedError(typeof(ExceptionlessClient), "Critical error in ExceptionlessClient constructor: {0}", ex.Message); } try { _localConfiguration = Config.LocalConfigurationDictionary.Create(_configuration.StoreId, this); } catch (Exception ex) { Log.FormattedError(typeof(ExceptionlessClient), "Critical error in ExceptionlessClient constructor: {0}", ex.Message); } _queue = new QueueManager(this, store); _queueTimer.Change(LocalConfiguration.QueuePoll, TimeSpan.Zero); #if SILVERLIGHT NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged; #else NetworkChange.NetworkAvailabilityChanged += NetworkChangeNetworkAvailabilityChanged; #endif }
private string GetVersionFromLoadedAssemblies(IExceptionlessLog log) { try { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && a != typeof(ExceptionlessClient).GetTypeInfo().Assembly && a != GetType().GetTypeInfo().Assembly && a != typeof(object).GetTypeInfo().Assembly)) { if (String.IsNullOrEmpty(assembly.FullName) || assembly.FullName.StartsWith("System.") || assembly.FullName.StartsWith("Microsoft.")) continue; string company = assembly.GetCompany(); if (!String.IsNullOrEmpty(company) && (String.Equals(company, "Exceptionless", StringComparison.OrdinalIgnoreCase) || String.Equals(company, "Microsoft Corporation", StringComparison.OrdinalIgnoreCase))) continue; #if !NETSTANDARD1_3 && !NETSTANDARD1_4 if (!assembly.GetReferencedAssemblies().Any(an => String.Equals(an.FullName, typeof(ExceptionlessClient).GetTypeInfo().Assembly.FullName))) continue; #endif string version = GetVersionFromAssembly(assembly); if (!String.IsNullOrEmpty(version)) return version; } } catch (Exception ex) { log.FormattedInfo(typeof(VersionPlugin), "Unable to get version from loaded assemblies. Error: {0}", ex.Message); } return null; }
private string GetVersionFromLoadedAssemblies(IExceptionlessLog log) { try { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && a != typeof(ExceptionlessClient).GetTypeInfo().Assembly&& a != GetType().GetTypeInfo().Assembly&& a != typeof(object).GetTypeInfo().Assembly)) { if (String.IsNullOrEmpty(assembly.FullName) || assembly.FullName.StartsWith("System.") || assembly.FullName.StartsWith("Microsoft.")) { continue; } string company = assembly.GetCompany(); if (!String.IsNullOrEmpty(company) && (String.Equals(company, "Exceptionless", StringComparison.OrdinalIgnoreCase) || String.Equals(company, "Microsoft Corporation", StringComparison.OrdinalIgnoreCase))) { continue; } #if !NETSTANDARD1_3 && !NETSTANDARD1_4 if (!assembly.GetReferencedAssemblies().Any(an => String.Equals(an.FullName, typeof(ExceptionlessClient).GetTypeInfo().Assembly.FullName))) { continue; } #endif string version = GetVersionFromAssembly(assembly); if (!String.IsNullOrEmpty(version)) { return(version); } } } catch (Exception ex) { log.FormattedInfo(typeof(VersionPlugin), "Unable to get version from loaded assemblies. Error: {0}", ex.Message); } return(null); }
private static Error ToErrorModelInternal(Exception exception, IExceptionlessLog log, bool isInner = false) { Type type = exception.GetType(); var error = new Error { Message = exception.GetMessage(), Type = type.FullName }; if (!isInner) { error.Modules = GetLoadedModules(log); } 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); } 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 = ToErrorModelInternal(exception.InnerException, log, true); } return(error); }
public WebLastReferenceIdManager(IExceptionlessLog log) { if (log == null) { throw new ArgumentNullException("log"); } Log = log; }
private static ModuleCollection GetLoadedModules(IExceptionlessLog log, bool includeSystem = false, bool includeDynamic = false) { var modules = new ModuleCollection(); #if !PORTABLE && !NETSTANDARD1_2 try { int id = 1; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (!includeDynamic && assembly.IsDynamic) { continue; } #if !NETSTANDARD1_3 && !NETSTANDARD1_4 try { if (!includeDynamic && String.IsNullOrEmpty(assembly.Location)) { continue; } } catch (SecurityException ex) { const string message = "An error occurred while getting the Assembly.Location value. This error will occur when when you are not running under full trust."; log.Error(typeof(ExceptionlessClient), ex, message); } #endif if (!includeSystem) { try { string publicKeyToken = assembly.GetAssemblyName().GetPublicKeyToken().ToHex(); if (_msPublicKeyTokens.Contains(publicKeyToken)) { continue; } var attrs = assembly.GetCustomAttributes(typeof(System.CodeDom.Compiler.GeneratedCodeAttribute)).ToList(); if (attrs.Count > 0) { continue; } } catch {} } var module = assembly.ToModuleInfo(); module.ModuleId = id; modules.Add(module); id++; } } catch (Exception ex) { log.Error(typeof(ExceptionlessClient), ex, "Error loading modules: " + ex.Message); } #endif return(modules); }
private string GetVersionFromRuntimeInfo(IExceptionlessLog log) { #if NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 try { var platformService = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default; return platformService.Application.ApplicationVersion; } catch (Exception ex) { log.FormattedInfo(typeof(VersionPlugin), "Unable to get Platform Services instance. Error: {0}", ex.Message); } #endif return null; }
public DefaultEventQueue(ExceptionlessConfiguration config, IExceptionlessLog log, ISubmissionClient client, IObjectStorage objectStorage, IJsonSerializer serializer, TimeSpan? processQueueInterval, TimeSpan? queueStartDelay) { _log = log; _config = config; _client = client; _storage = objectStorage; _serializer = serializer; if (processQueueInterval.HasValue) _processQueueInterval = processQueueInterval.Value; _queueTimer = new Timer(OnProcessQueue, null, queueStartDelay ?? TimeSpan.FromSeconds(2), _processQueueInterval); }
private static ModuleCollection GetLoadedModules(IExceptionlessLog log, bool includeSystem = false, bool includeDynamic = false) { var modules = new ModuleCollection(); int id = 1; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (!includeDynamic && assembly.IsDynamic) { continue; } try { if (!includeDynamic && String.IsNullOrEmpty(assembly.Location)) { continue; } } catch (SecurityException ex) { const string message = "An error occurred while getting the Assembly.Location value. This error will occur when when you are not running under full trust."; log.Error(typeof(ExceptionlessClient), ex, message); } if (!includeSystem) { try { string publicKeyToken = assembly.GetAssemblyName().GetPublicKeyToken().ToHex(); if (_msPublicKeyTokens.Contains(publicKeyToken)) { continue; } object[] attrs = assembly.GetCustomAttributes(typeof(GeneratedCodeAttribute), true); if (attrs.Length > 0) { continue; } } catch {} } var module = assembly.ToModuleInfo(); if (module.ModuleId > 0) { continue; } module.ModuleId = id; modules.Add(module); id++; } return(modules); }
private string GetVersionFromRuntimeInfo(IExceptionlessLog log) { #if NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 try { var platformService = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default; return(platformService.Application.ApplicationVersion); } catch (Exception ex) { log.FormattedInfo(typeof(VersionPlugin), "Unable to get Platform Services instance. Error: {0}", ex.Message); } #endif return(null); }
public DefaultEventQueue(ExceptionlessConfiguration config, IExceptionlessLog log, ISubmissionClient client, IObjectStorage objectStorage, IJsonSerializer serializer, TimeSpan?processQueueInterval, TimeSpan?queueStartDelay) { _log = log; _config = config; _client = client; _storage = objectStorage; _serializer = serializer; if (processQueueInterval.HasValue) { _processQueueInterval = processQueueInterval.Value; } _queueTimer = new Timer(OnProcessQueue, null, queueStartDelay ?? TimeSpan.FromSeconds(2), _processQueueInterval); }
/// <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; }
public static List<Type> GetTypes(IExceptionlessLog log) { var types = new List<Type>(); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { try { if (assembly.IsDynamic) continue; types.AddRange(assembly.GetExportedTypes()); } catch (Exception ex) { log.Error(typeof(ExceptionlessExtraConfigurationExtensions), ex, String.Format("An error occurred while getting types for assembly \"{0}\".", assembly)); } } return types; }
public static List<Type> GetTypes(IExceptionlessLog log) { var types = new List<Type>(); #if !PORTABLE && !NETSTANDARD1_2 var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { try { if (assembly.IsDynamic) continue; types.AddRange(assembly.GetExportedTypes()); } catch (Exception ex) { log.Error(typeof(AssemblyHelper), ex, String.Format("An error occurred while getting types for assembly \"{0}\".", assembly)); } } #endif return types; }
private string GetVersion(IExceptionlessLog log) { if (_appVersionLoaded) { return(_appVersion); } var entryAssembly = GetEntryAssembly(log); try { string version = GetVersionFromAssembly(entryAssembly); if (!String.IsNullOrEmpty(version)) { _appVersion = version; _appVersionLoaded = true; return(_appVersion); } } catch (Exception ex) { log.FormattedError(typeof(VersionPlugin), ex, "Unable to get version from loaded assemblies. Error: {0}", ex.Message); } #if NETSTANDARD2_0 try { var platformService = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default; _appVersion = platformService.Application.ApplicationVersion; _appVersionLoaded = true; return(_appVersion); } catch (Exception ex) { log.FormattedError(typeof(VersionPlugin), ex, "Unable to get Platform Services instance. Error: {0}", ex.Message); } #endif _appVersion = null; _appVersionLoaded = true; return(null); }
public static List <Type> GetTypes(IExceptionlessLog log) { var types = new List <Type>(); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { try { if (assembly.IsDynamic) { continue; } types.AddRange(assembly.GetExportedTypes()); } catch (Exception ex) { log.Error(typeof(ExceptionlessExtraConfigurationExtensions), ex, String.Format("An error occurred while getting types for assembly \"{0}\".", assembly)); } } return(types); }
private Assembly GetEntryAssembly(IExceptionlessLog log) { var entryAssembly = Assembly.GetEntryAssembly(); if (IsUserAssembly(entryAssembly)) { return(entryAssembly); } try { var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && a != typeof(ExceptionlessClient).GetTypeInfo().Assembly && a != GetType().GetTypeInfo().Assembly && a != typeof(object).GetTypeInfo().Assembly); return(assemblies.FirstOrDefault(a => IsUserAssembly(a))); } catch (Exception ex) { log.FormattedError(typeof(VersionPlugin), ex, "Unable to get entry assembly. Error: {0}", ex.Message); } return(null); }
public static List <Type> GetTypes(IExceptionlessLog log) { var types = new List <Type>(); #if !PORTABLE && !NETSTANDARD1_2 var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { try { if (assembly.IsDynamic) { continue; } types.AddRange(assembly.GetExportedTypes()); } catch (Exception ex) { log.Error(typeof(AssemblyHelper), ex, String.Format("An error occurred while getting types for assembly \"{0}\".", assembly)); } } #endif return(types); }
public static void FormattedDebug(this IExceptionlessLog log, string format, params object[] args) { log.Debug(GetMessage(format, args)); }
public DefaultEventQueue(ExceptionlessConfiguration config, IExceptionlessLog log, ISubmissionClient client, IObjectStorage objectStorage, IJsonSerializer serializer): this(config, log, client, objectStorage, serializer, null, null) {}
public DefaultEnvironmentInfoCollector(IExceptionlessLog log) { _log = log; }
public SafeExceptionlessLog(IExceptionlessLog log, IExceptionlessLog fallbackLog = null) { _log = log; _fallbackLog = fallbackLog ?? new NullExceptionlessLog(); MinimumLogLevel = LogLevel.Info; }
public static void FormattedError(this IExceptionlessLog log, Exception exception, string format, params object[] args) { log.Error(String.Format(format, args), exception: exception); }
public static void FormattedTrace(this IExceptionlessLog log, Type source, string format, params object[] args) { log.Trace(String.Format(format, args), GetSourceName(source)); }
public static void FormattedError(this IExceptionlessLog log, Type source, Exception exception, string format, params object[] args) { log.Error(String.Format(format, args), GetSourceName(source), exception); }
private static void PopulateStackTrace(this Error error, Error root, Exception exception, IExceptionlessLog log) { StackFrame[] frames = null; try { var st = new StackTrace(exception, true); frames = st.GetFrames(); } catch {} if (frames == null) return; foreach (StackFrame frame in frames) { var stackFrame = new Models.Data.StackFrame { LineNumber = frame.GetFileLineNumber(), Column = frame.GetFileColumnNumber(), FileName = frame.GetFileName() }; try { stackFrame.Data["ILOffset"] = frame.GetILOffset(); stackFrame.Data["NativeOffset"] = frame.GetNativeOffset(); } catch (Exception ex) { log.Error(typeof(ExceptionlessClient), ex, "Error populating StackFrame offset info: " + ex.Message); } try { stackFrame.PopulateMethod(root, frame.GetMethod()); } catch (Exception ex) { log.Error(typeof(ExceptionlessClient), ex, "Error populating StackFrame method info: " + ex.Message); } error.StackTrace.Add(stackFrame); } }
private static ModuleCollection GetLoadedModules(IExceptionlessLog log, bool includeSystem = false, bool includeDynamic = false) { var modules = new ModuleCollection(); try { int id = 1; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { if (!includeDynamic && assembly.IsDynamic) continue; try { if (!includeDynamic && String.IsNullOrEmpty(assembly.Location)) continue; } catch (SecurityException ex) { const string message = "An error occurred while getting the Assembly.Location value. This error will occur when when you are not running under full trust."; log.Error(typeof(ExceptionlessClient), ex, message); } if (!includeSystem) { try { string publicKeyToken = assembly.GetAssemblyName().GetPublicKeyToken().ToHex(); if (_msPublicKeyTokens.Contains(publicKeyToken)) continue; object[] attrs = assembly.GetCustomAttributes(typeof(GeneratedCodeAttribute), true); if (attrs.Length > 0) continue; } catch {} } var module = assembly.ToModuleInfo(); module.ModuleId = id; modules.Add(module); id++; } } catch (Exception ex) { log.Error(typeof(ExceptionlessClient), ex, "Error loading modules: " + ex.Message); } return modules; }
private static ModuleCollection GetLoadedModules( #if EMBEDDED IExceptionlessLog log, #endif bool includeSystem = false, bool includeDynamic = false) { var modules = new ModuleCollection(); int id = 1; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { #if PFX_LEGACY_3_5 try { if (!includeDynamic && assembly.ManifestModule is System.Reflection.Emit.MethodBuilder) continue; } catch (NotImplementedException ex) { #if EMBEDDED log.Error(ex, "An error occurred while checking if the current assembly is a dynamic assembly."); #endif } #else if (!includeDynamic && assembly.IsDynamic) continue; try { if (!includeDynamic && String.IsNullOrEmpty(assembly.Location)) continue; } catch (SecurityException ex) { const string message = "An error occurred while getting the Assembly.Location value. This error will occur when when you are not running under full trust."; #if EMBEDDED log.Error(typeof(ExceptionlessClient), ex, message); #else Trace.WriteLine(String.Format("{0} Exception: {1}", message, ex)); #endif } #endif if (!includeSystem) { try { string publicKeyToken = assembly.GetAssemblyName().GetPublicKeyToken().ToHex(); if (_msPublicKeyTokens.Contains(publicKeyToken)) continue; object[] attrs = assembly.GetCustomAttributes(typeof(GeneratedCodeAttribute), true); if (attrs.Length > 0) continue; } catch {} } #if EMBEDDED var module = assembly.ToModuleInfo(log); module.ModuleId = id; modules.Add(assembly.ToModuleInfo(log)); #else var module = assembly.ToModuleInfo(); module.ModuleId = id; modules.Add(assembly.ToModuleInfo()); #endif id++; } return modules; }
/// <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) { return(ToErrorModelInternal(exception, log)); }
public static Module ToModuleInfo(this System.Reflection.Module module, IExceptionlessLog log = null) { return ToModuleInfo(module.Assembly, log); }
public TestConfigurationAndLogAccessor(IExceptionlessLog log = null) { Log = log ?? new NullExceptionlessLog(); Configuration = new ClientConfiguration(); }
public static void UseLogger(this ExceptionlessConfiguration config, IExceptionlessLog logger) { config.Resolver.Register<IExceptionlessLog>(new SafeExceptionlessLog(logger)); }
public static void Error(this IExceptionlessLog log, Type source, Exception exception, string message) { log.Error(message, GetSourceName(source), exception); }
public DefaultEnvironmentInfoCollector(ExceptionlessConfiguration config, IExceptionlessLog log) { _config = config; _log = log; }
public static void Trace(this IExceptionlessLog log, Type source, string message) { log.Trace(message, GetSourceName(source)); }
public WebLastReferenceIdManager(IExceptionlessLog log) { if (log == null) throw new ArgumentNullException("log"); Log = log; }
public static void Error(this IExceptionlessLog log, Exception exception, string message) { log.Error(message, exception: exception); }
public ErrorEnrichment(IExceptionlessLog log) { _log = log; }
public static void FormattedWarn(this IExceptionlessLog log, string format, params object[] args) { log.Warn(String.Format(format, args)); }
public static Module ToModuleInfo(this Assembly assembly, IExceptionlessLog log = null) { if (assembly == null) { return(null); } if (log == null) { log = new NullExceptionlessLog(); } Module module = _moduleCache.GetOrAdd(assembly.FullName, k => { var mod = new Module(); AssemblyName name = assembly.GetAssemblyName(); if (name != null) { mod.Name = name.Name; mod.Version = name.Version.ToString(); byte[] pkt = name.GetPublicKeyToken(); if (pkt.Length > 0) { mod.Data["PublicKeyToken"] = pkt.ToHex(); } } string infoVersion = assembly.GetInformationalVersion(); if (!String.IsNullOrEmpty(infoVersion) && infoVersion != mod.Version) { mod.Data["ProductVersion"] = infoVersion; } string fileVersion = assembly.GetFileVersion(); if (!String.IsNullOrEmpty(fileVersion) && fileVersion != mod.Version) { mod.Data["FileVersion"] = fileVersion; } DateTime?creationTime = assembly.GetCreationTime(); if (creationTime.HasValue) { mod.CreatedDate = creationTime.Value; } DateTime?lastWriteTime = assembly.GetLastWriteTime(); if (lastWriteTime.HasValue) { mod.ModifiedDate = lastWriteTime.Value; } return(mod); }); if (module != null) { if (assembly == Assembly.GetEntryAssembly()) { module.IsEntry = true; } } return(module); }
public DefaultDuplicateChecker(IExceptionlessLog log) { _log = log; }
public SafeExceptionlessLog(IExceptionlessLog log, IExceptionlessLog fallbackLog = null) { _log = log; _fallbackLog = fallbackLog ?? new NullExceptionlessLog(); }
public static void UseLogger(this ExceptionlessConfiguration config, IExceptionlessLog logger) { config.Resolver.Register <IExceptionlessLog>(new SafeExceptionlessLog(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionlessClient" /> class. /// </summary> internal ExceptionlessClient(IQueueStore store = null, IExceptionlessLog log = null) { _queueTimer = new Timer(OnQueueTimer, null, Timeout.Infinite, Timeout.Infinite); _log = log ?? new NullExceptionlessLog(); try { _configuration = Config.ClientConfiguration.Create(this); Log.FormattedTrace(typeof(ExceptionlessClient), "Configuration Values: ApiKey={0}, EnableSSL={1}, Enabled={2}, ServerUrl={3}", _configuration.ApiKey, _configuration.EnableSSL, _configuration.Enabled, _configuration.ServerUrl); } catch (Exception ex) { Log.FormattedError(typeof(ExceptionlessClient), "Critical error in ExceptionlessClient constructor: {0}", ex.Message); } try { _localConfiguration = Config.LocalConfigurationDictionary.Create(_configuration.StoreId, this); } catch (Exception ex) { Log.FormattedError(typeof(ExceptionlessClient), "Critical error in ExceptionlessClient constructor: {0}", ex.Message); } _queue = new QueueManager(this, store); _queueTimer.Change(LocalConfiguration.QueuePoll, TimeSpan.Zero); #if SILVERLIGHT NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged; #else NetworkChange.NetworkAvailabilityChanged += NetworkChangeNetworkAvailabilityChanged; #endif }
private static ModuleCollection GetLoadedModules( #if EMBEDDED IExceptionlessLog log, #endif bool includeSystem = false, bool includeDynamic = false) { var modules = new ModuleCollection(); int id = 1; foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { #if PFX_LEGACY_3_5 try { if (!includeDynamic && assembly.ManifestModule is System.Reflection.Emit.MethodBuilder) { continue; } } catch (NotImplementedException ex) { #if EMBEDDED log.Error(ex, "An error occurred while checking if the current assembly is a dynamic assembly."); #endif } #else if (!includeDynamic && assembly.IsDynamic) { continue; } try { if (!includeDynamic && String.IsNullOrEmpty(assembly.Location)) { continue; } } catch (SecurityException ex) { const string message = "An error occurred while getting the Assembly.Location value. This error will occur when when you are not running under full trust."; #if EMBEDDED log.Error(typeof(ExceptionlessClient), ex, message); #else Trace.WriteLine(String.Format("{0} Exception: {1}", message, ex)); #endif } #endif if (!includeSystem) { try { string publicKeyToken = assembly.GetAssemblyName().GetPublicKeyToken().ToHex(); if (_msPublicKeyTokens.Contains(publicKeyToken)) { continue; } object[] attrs = assembly.GetCustomAttributes(typeof(GeneratedCodeAttribute), true); if (attrs.Length > 0) { continue; } } catch {} } #if EMBEDDED var module = assembly.ToModuleInfo(log); module.ModuleId = id; modules.Add(assembly.ToModuleInfo(log)); #else var module = assembly.ToModuleInfo(); module.ModuleId = id; modules.Add(assembly.ToModuleInfo()); #endif id++; } return(modules); }
public static Module ToModuleInfo(this Assembly assembly, IExceptionlessLog log = null) { if (assembly == null) return null; if (log == null) log = new NullExceptionlessLog(); Module module = _moduleCache.GetOrAdd(assembly.FullName, k => { var mod = new Module(); AssemblyName name = assembly.GetAssemblyName(); if (name != null) { mod.Name = name.Name; mod.Version = name.Version.ToString(); byte[] pkt = name.GetPublicKeyToken(); if (pkt.Length > 0) mod.Data["PublicKeyToken"] = pkt.ToHex(); } string infoVersion = assembly.GetInformationalVersion(); if (!String.IsNullOrEmpty(infoVersion) && infoVersion != mod.Version) mod.Data["ProductVersion"] = infoVersion; string fileVersion = assembly.GetFileVersion(); if (!String.IsNullOrEmpty(fileVersion) && fileVersion != mod.Version) mod.Data["FileVersion"] = fileVersion; DateTime? creationTime = assembly.GetCreationTime(); if (creationTime.HasValue) mod.CreatedDate = creationTime.Value; DateTime? lastWriteTime = assembly.GetLastWriteTime(); if (lastWriteTime.HasValue) mod.ModifiedDate = lastWriteTime.Value; return mod; }); if (module != null) { if (assembly == Assembly.GetEntryAssembly()) module.IsEntry = true; } return module; }
public DefaultEventQueue(ExceptionlessConfiguration config, IExceptionlessLog log, ISubmissionClient client, IObjectStorage objectStorage, IJsonSerializer serializer) : this(config, log, client, objectStorage, serializer, null, null) { }
/// <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); }
public static Module ToModuleInfo(this System.Reflection.Module module, IExceptionlessLog log = null) { return(ToModuleInfo(module.Assembly, log)); }
private static void PopulateStackTrace(this Error error, Error root, Exception exception, IExceptionlessLog log) { StackFrame[] frames = null; try { var st = new StackTrace(exception, true); frames = st.GetFrames(); } catch {} if (frames == null) { return; } foreach (StackFrame frame in frames) { var stackFrame = new Models.Data.StackFrame { LineNumber = frame.GetFileLineNumber(), Column = frame.GetFileColumnNumber(), FileName = frame.GetFileName() }; try { stackFrame.Data["ILOffset"] = frame.GetILOffset(); #if NET45 stackFrame.Data["NativeOffset"] = frame.GetNativeOffset(); #endif } catch (Exception ex) { log.Error(typeof(ExceptionlessClient), ex, "Error populating StackFrame offset info: " + ex.Message); } try { stackFrame.PopulateMethod(root, frame.GetMethod()); } catch (Exception ex) { log.Error(typeof(ExceptionlessClient), ex, "Error populating StackFrame method info: " + ex.Message); } error.StackTrace.Add(stackFrame); } }
public DefaultDuplicateChecker(IExceptionlessLog log) { _log = log; }
/// <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; }