Ejemplo n.º 1
0
        private async Task <Response> RetryWithSplit(TData data)
        {
            var newBatches = Split(data);

            if (newBatches == null)
            {
                _logger.Error($@"Cannot send data because it exceeds the size limit and cannot be split.");
                return(Response.Failure(HttpStatusCode.RequestEntityTooLarge, "Cannot send data because it exceeds size limit and cannot be further split."));
            }

            _logger.Warning("Splitting the data and retrying.");

            var taskList = new Task <Response> [newBatches.Length];

            for (var i = 0; i < newBatches.Length; i++)
            {
                taskList[i] = SendDataAsync(newBatches[i]);
            }

            var responses = await Task.WhenAll(taskList);

            if (responses.All(x => x.ResponseStatus == NewRelicResponseStatus.Success))
            {
                return(Response.Success);
            }

            return(Response.Failure(HttpStatusCode.Ambiguous, $"{responses.Count(x=>x.ResponseStatus != NewRelicResponseStatus.Success)} of {responses.Length} requests were NOT successful."));
        }
        public void TestLogging()
        {
            var loggerFactory     = new LoggerFactory();
            var customLogProvider = new CustomLoggerProvider();

            loggerFactory.AddProvider(customLogProvider);

            var tl = new TelemetryLogging(loggerFactory);

            var ex = new Exception("Test Exception level logging");

            tl.Debug("debug level logging message.");
            tl.Info("information level logging message.");
            tl.Warning("warning level logging message.");
            tl.Error("error level logging message.");
            tl.Exception(ex);

            Assert.True(customLogProvider.LogOutput.ContainsKey("NewRelic.Telemetry"));
            var logs = customLogProvider.LogOutput["NewRelic.Telemetry"];

            Assert.Equal(5, logs.Count);
            Assert.Contains("NewRelic Telemetry: debug level logging message.", logs);
            Assert.Contains("NewRelic Telemetry: information level logging message.", logs);
            Assert.Contains("NewRelic Telemetry: warning level logging message.", logs);
            Assert.Contains("NewRelic Telemetry: error level logging message.", logs);
            Assert.Contains($"NewRelic Telemetry: Exception {ex.GetType().FullName}: {ex.Message}", logs);
        }