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 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; }
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 bool IsDuplicate(Event ev) { if (!ev.IsError) { return(false); } InnerError current = ev.GetError(); DateTime repeatWindow = DateTime.Now.AddSeconds(-2); while (current != null) { int hashCode = current.GetHashCode(); _log.FormattedTrace(typeof(ExceptionlessClient), "Checking for duplicate error: hash={0} type={1}", hashCode, current.Type); _log.FormattedTrace(typeof(ExceptionlessClient), "Error contents: {0}", current.ToString()); // make sure that we don't process the same error multiple times within 2 seconds. if (_recentlyProcessedErrors.Any(s => s.Item1 == hashCode && s.Item2 >= repeatWindow)) { _log.FormattedInfo(typeof(ExceptionlessClient), "Ignoring duplicate exception: type={0}", current.Type); return(true); } // add this exception to our list of recent errors that we have processed. _recentlyProcessedErrors.Enqueue(Tuple.Create(hashCode, DateTime.Now)); // only keep the last 10 recent errors Tuple <int, DateTime> temp; while (_recentlyProcessedErrors.Count > 10) { _recentlyProcessedErrors.TryDequeue(out temp); } current = current.Inner; } return(false); }
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; } }
public EnvironmentInfo GetEnvironmentInfo() { if (_environmentInfo != null) { return(_environmentInfo); } var info = new EnvironmentInfo(); ComputerInfo computerInfo = null; try { computerInfo = new ComputerInfo(); } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get computer info. Error message: {0}", ex.Message); } try { if (computerInfo != null) { info.OSName = computerInfo.OSFullName; } if (computerInfo != null) { info.OSVersion = computerInfo.OSVersion; } } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get operating system version. Error message: {0}", ex.Message); } try { if (computerInfo != null) { info.TotalPhysicalMemory = Convert.ToInt64(computerInfo.TotalPhysicalMemory); } if (computerInfo != null) { info.AvailablePhysicalMemory = Convert.ToInt64(computerInfo.AvailablePhysicalMemory); } } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get physical memory. Error message: {0}", ex.Message); } try { info.ProcessorCount = Environment.ProcessorCount; } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get processor count. Error message: {0}", ex.Message); } try { info.MachineName = Environment.MachineName; } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get machine name. Error message: {0}", ex.Message); } try { IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); if (hostEntry != null && hostEntry.AddressList.Any()) { info.IpAddress = String.Join(", ", hostEntry.AddressList.Where(x => x.AddressFamily == AddressFamily.InterNetwork).Select(a => a.ToString()).ToArray()); } } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get ip address. Error message: {0}", ex.Message); } try { Process proc = Process.GetCurrentProcess(); info.ProcessMemorySize = proc.PrivateMemorySize64; } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get process memory size. Error message: {0}", ex.Message); } try { info.CommandLine = Environment.CommandLine; } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get command line. Error message: {0}", ex.Message); } try { info.ProcessId = KernelNativeMethods.GetCurrentProcessId().ToString(NumberFormatInfo.InvariantInfo); } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get process id. Error message: {0}", ex.Message); } try { info.ProcessName = GetProcessName(); } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get process name. Error message: {0}", ex.Message); } try { info.ThreadId = KernelNativeMethods.GetCurrentThreadId().ToString(NumberFormatInfo.InvariantInfo); } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get thread id. Error message: {0}", ex.Message); } try { info.Architecture = Is64BitOperatingSystem() ? "x64" : "x86"; } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get CPU architecture. Error message: {0}", ex.Message); } try { info.RuntimeVersion = Environment.Version.ToString(); } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get CLR version. Error message: {0}", ex.Message); } try { info.Data.Add("AppDomainName", AppDomain.CurrentDomain.FriendlyName); } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get AppDomain friendly name. Error message: {0}", ex.Message); } try { info.ThreadName = Thread.CurrentThread.Name; } catch (Exception ex) { _log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get current thread name. Error message: {0}", ex.Message); } _environmentInfo = info; return(_environmentInfo); }
public void Process() { if (_processingQueue) { return; } _log.Trace(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()); DateTime maxCreatedDate = DateTime.Now; var batch = _storage.GetEventBatch(_config.GetQueueName(), _serializer, maxCreatedDate: maxCreatedDate); while (batch.Any()) { bool deleteBatch = true; try { var response = _client.PostEvents(batch.Select(b => b.Item2), _config, _serializer); if (response.Success) { _log.FormattedInfo(typeof(DefaultEventQueue), "Sent {0} events to the server.", batch.Count); } 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.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, maxCreatedDate: maxCreatedDate); } } catch (Exception ex) { _log.Error(typeof(DefaultEventQueue), ex, String.Concat("An error occurred while processing the queue: ", ex.Message)); SuspendProcessing(); } finally { _processingQueue = false; } }