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); }
public void Error(string message, string source = null, Exception exception = null) { try { _log.Error(message, source, exception); } catch (Exception ex) { try { _fallbackLog.Error("Error writing to log.", null, ex); _fallbackLog.Error(message, source, exception); } catch {} } }
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 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 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; }
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 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 void Process() { if (_processingQueue) { return; } _log.Info(typeof(DefaultEventQueue), "Processing queue..."); if (!_config.Enabled) { _log.Info(typeof(DefaultEventQueue), "Configuration is disabled. The queue will not be processed."); return; } _processingQueue = true; try { _storage.CleanupQueueFiles(_config.GetQueueName()); _storage.ReleaseStaleLocks(_config.GetQueueName()); var batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer); while (batch.Any()) { bool deleteBatch = true; try { var response = _client.PostEvents(batch.Select(b => b.Item2), _config, _serializer); if (response.ServiceUnavailable) { // You are currently over your rate limit or the servers are under stress. _log.Error(typeof(DefaultEventQueue), "Server returned service unavailable."); SuspendProcessing(); deleteBatch = false; } else if (response.PaymentRequired) { // If the organization over the rate limit then discard the event. _log.Info(typeof(DefaultEventQueue), "Too many events have been submitted, please upgrade your plan."); SuspendProcessing(discardFutureQueuedItems: true, clearQueue: true); } else if (response.UnableToAuthenticate) { // The api key was suspended or could not be authorized. _log.Info(typeof(DefaultEventQueue), "Unable to authenticate, please check your configuration. The event will not be submitted."); SuspendProcessing(TimeSpan.FromMinutes(15)); } else if (response.NotFound || response.BadRequest) { // The service end point could not be found. _log.Error(typeof(DefaultEventQueue), "Unable to reach the service end point, please check your configuration. The event will not be submitted."); SuspendProcessing(TimeSpan.FromHours(4)); } else if (!response.Success) { _log.Error(typeof(DefaultEventQueue), String.Format("An error occurred while submitting events: {0}", response.Message)); SuspendProcessing(); deleteBatch = false; } } catch (Exception ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while submitting events: ", ex.Message)); SuspendProcessing(); deleteBatch = false; } if (deleteBatch) { _storage.DeleteBatch(batch); } else { _storage.ReleaseBatch(batch); } if (!deleteBatch || IsQueueProcessingSuspended) { break; } batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer); } } catch (Exception ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while processing the queue: ", ex.Message)); SuspendProcessing(); } finally { _processingQueue = false; } }
public static void Error(this IExceptionlessLog log, Exception exception, string message) { log.Error(message, exception: exception); }
public static void FormattedError(this IExceptionlessLog log, Exception exception, string format, params object[] args) { log.Error(GetMessage(format, args), exception: exception); }
public static void FormattedError(this IExceptionlessLog log, Type source, Exception exception, string format, params object[] args) { log.Error(GetMessage(format, args), GetSourceName(source), exception); }
public void Process() { if (IsQueueProcessingSuspended) { return; } _log.Info(typeof(DefaultEventQueue), "Processing queue..."); if (!_config.Enabled) { _log.Info(typeof(DefaultEventQueue), "Configuration is disabled. The queue will not be processed."); return; } if (_processingQueue) { _log.Info(typeof(DefaultEventQueue), "The queue is already being processed."); return; } _processingQueue = true; try { var batch = _storage.GetEventBatch(_serializer); if (!batch.Any()) { _log.Info(typeof(DefaultEventQueue), "There are no events in the queue to process."); return; } bool deleteBatch = true; try { var response = _client.Submit(batch.Select(b => b.Item2), _config, _serializer); if (response.ServiceUnavailable) { // You are currently over your rate limit or the servers are under stress. _log.Error(typeof(DefaultEventQueue), "Server returned service unavailable."); SuspendProcessing(); deleteBatch = false; } else if (response.PaymentRequired) { // If the organization over the rate limit then discard the error. _log.Info(typeof(DefaultEventQueue), "Too many errors have been submitted, please upgrade your plan."); SuspendProcessing(discardFutureQueuedItems: true, clearQueue: true); } else if (response.UnableToAuthenticate) { // The api key was suspended or could not be authorized. _log.Info(typeof(DefaultEventQueue), "Unable to authenticate, please check your configuration. The error will not be submitted."); SuspendProcessing(TimeSpan.FromMinutes(15)); } else if (response.NotFound) { // The service end point could not be found. _log.Error(typeof(DefaultEventQueue), "Unable to reach the service end point, please check your configuration. The error will not be submitted."); SuspendProcessing(TimeSpan.FromHours(4)); } else if (!response.Success) { deleteBatch = false; } } catch (Exception ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while submitting events: ", ex.Message)); deleteBatch = false; } if (deleteBatch) { _storage.DeleteBatch(batch); } else { _storage.ReleaseBatch(batch); } } catch (Exception ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while processing the queue: ", ex.Message)); } finally { _processingQueue = false; } //if (response.ShouldUpdateConfiguration(LocalConfiguration.CurrentConfigurationVersion)) // UpdateConfiguration(true); //completed = new SendErrorCompletedEventArgs(id, exception, false, error); //OnSendErrorCompleted(completed); // TODO: Check to see if the configuration needs to be updated. }
public static void Error(this IExceptionlessLog log, Type source, Exception exception, string message) { log.Error(message, GetSourceName(source), exception); }
public static void FormattedError(this IExceptionlessLog log, Type source, string format, params object[] args) { log.Error(String.Format(format, args), GetSourceName(source)); }
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; }
public static void FormattedError(this IExceptionlessLog log, string format, params object[] args) { log.Error(String.Format(format, args)); }
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); } }
public void Process() { if (_processingQueue) { return; } if (!_config.Enabled) { _log.Info(typeof(DefaultEventQueue), "Configuration is disabled. The queue will not be processed."); return; } _log.Trace(typeof(DefaultEventQueue), "Processing queue..."); _processingQueue = true; try { _storage.CleanupQueueFiles(_config.GetQueueName(), _config.QueueMaxAge, _config.QueueMaxAttempts); _storage.ReleaseStaleLocks(_config.GetQueueName()); DateTime maxCreatedDate = DateTime.Now; int batchSize = _config.SubmissionBatchSize; var batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer, batchSize, maxCreatedDate); while (batch.Any()) { bool deleteBatch = true; try { var events = batch.Select(b => b.Item2).ToList(); var response = _client.PostEvents(events, _config, _serializer); if (response.Success) { _log.FormattedInfo(typeof(DefaultEventQueue), "Sent {0} events to \"{1}\".", batch.Count, _config.ServerUrl); } else if (response.ServiceUnavailable) { // You are currently over your rate limit or the servers are under stress. _log.Error(typeof(DefaultEventQueue), "Server returned service unavailable."); SuspendProcessing(); deleteBatch = false; } else if (response.PaymentRequired) { // If the organization over the rate limit then discard the event. _log.Info(typeof(DefaultEventQueue), "Too many events have been submitted, please upgrade your plan."); SuspendProcessing(discardFutureQueuedItems: true, clearQueue: true); } else if (response.UnableToAuthenticate) { // The api key was suspended or could not be authorized. _log.Info(typeof(DefaultEventQueue), "Unable to authenticate, please check your configuration. The event will not be submitted."); SuspendProcessing(TimeSpan.FromMinutes(15)); } else if (response.NotFound || response.BadRequest) { // The service end point could not be found. _log.FormattedError(typeof(DefaultEventQueue), "Error while trying to submit data: {0}", response.Message); SuspendProcessing(TimeSpan.FromHours(4)); } else if (response.RequestEntityTooLarge) { if (batchSize > 1) { _log.Error(typeof(DefaultEventQueue), "Event submission discarded for being too large. The event will be retried with a smaller batch size."); batchSize = Math.Max(1, (int)Math.Round(batchSize / 1.5d, 0)); deleteBatch = false; } else { _log.Error(typeof(DefaultEventQueue), "Event submission discarded for being too large. The event will not be submitted."); } } else if (!response.Success) { _log.Error(typeof(DefaultEventQueue), String.Concat("An error occurred while submitting events: ", response.Message)); SuspendProcessing(); deleteBatch = false; } OnEventsPosted(new EventsPostedEventArgs { Events = events, Response = response }); } catch (AggregateException ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while submitting events: ", ex.Flatten().Message)); SuspendProcessing(); deleteBatch = false; } catch (Exception ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while submitting events: ", ex.Message)); SuspendProcessing(); deleteBatch = false; } if (deleteBatch) { _storage.DeleteBatch(batch); } else { _storage.ReleaseBatch(batch); } if (!deleteBatch || IsQueueProcessingSuspended) { break; } batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer, batchSize, maxCreatedDate); } } catch (Exception ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while processing the queue: ", ex.Message)); SuspendProcessing(); } finally { _processingQueue = false; } }
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; }