コード例 #1
0
 protected async Task LogException(Exception ex, IExceptionService exceptionService, SettingsFactory settingsFactory, Settings settings)
 {
     try
     {
         Console.WriteLine(ex.ToString());
         if (!string.IsNullOrEmpty(settings.ExceptionLoggingDomainId) && !string.IsNullOrEmpty(settings.LogApiBaseAddress))
             await exceptionService.Create(
                 settingsFactory.CreateLog(settings, GetAccessToken()),
                 Guid.Parse(settings.ExceptionLoggingDomainId),
                 ex
                 );
     }
     catch (Exception innerException)
     {
         Console.Write(innerException.ToString());
     }
 }
コード例 #2
0
        private static async Task GenerateEntries(AccountInterfaceModels.Domain domain)
        {
            DateTime start = DateTime.UtcNow;

            using ILifetimeScope scope = _diContainer.BeginLifetimeScope();
            IMetricService         metricService    = scope.Resolve <IMetricService>();
            ITraceService          traceService     = scope.Resolve <ITraceService>();
            IExceptionService      exceptionService = scope.Resolve <IExceptionService>();
            SettingsFactory        settingsFactory  = scope.Resolve <SettingsFactory>();
            LogSettings            logSettings      = settingsFactory.CreateLog(_settings);
            Queue <Task <Metric> > queue            = new Queue <Task <Metric> >();

            Console.WriteLine($"Entry generation started at {start:HH:mm:ss}");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"Entry generation started at {start:HH:mm:ss}", new { Date = DateTime.UtcNow });

            for (int i = 0; i < _settings.EntryCount; i += 1)
            {
                if (queue.Count >= _settings.ConcurentTaskCount)
                {
                    try
                    {
                        await queue.Dequeue();
                    }
                    catch (System.Exception ex)
                    {
                        await exceptionService.Create(settingsFactory.CreateLog(_settings), domain.DomainId.Value, ex);
                    }
                }
                queue.Enqueue(metricService.Create(logSettings, domain.DomainId.Value, DateTime.UtcNow, "bl-t-client-gen", DateTime.UtcNow.Subtract(new DateTime(2000, 1, 1)).TotalSeconds));
            }
            await Task.WhenAll(queue);

            DateTime end = DateTime.UtcNow;

            Console.WriteLine($"Entry generation ended at {end:HH:mm:ss} and took {end.Subtract(start).TotalMinutes:0.0##} minutes");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"Entry generation ended at {end:HH:mm:ss} and took {end.Subtract(start).TotalMinutes:0.0##} minutes");

            Console.WriteLine($"{_settings.EntryCount} records created");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"{_settings.EntryCount} records created");

            double rate = Math.Round((double)_settings.EntryCount / end.Subtract(start).TotalSeconds, 3, MidpointRounding.ToEven);

            Console.WriteLine($"at {rate} records per second");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"at {rate} records per second");
        }