コード例 #1
0
        private static async Task <StatusCodeResult> RedisUpsert(ProcessingUpdate update, AppInsightsLogger appInsightsLogger, string redisOperation)
        {
            IDatabase db = null;

            try
            {
                db = RedisConnection.GetDatabase();
            }
            catch (Exception ex)
            {
                appInsightsLogger.LogError(ex, update.ApiPath);
                appInsightsLogger.LogRedisUpsert("Redis upsert failed.", redisOperation, DateTime.UtcNow.ToString(), update.ApiPath);
                return(new StatusCodeResult(500));
            }

            try
            {
                var keyname  = APP_INSIGHTS_REQUESTS_KEY_NAME + "/" + update.ServiceCluster + update.ApiPath;
                var newCount = await db.StringIncrementAsync(keyname, update.IncrementBy - update.DecrementBy);

                appInsightsLogger.LogMetric(keyname, newCount, update.ApiPath);
                return(new StatusCodeResult(200));
            }
            catch (Exception ex)
            {
                appInsightsLogger.LogError(ex, update.ApiPath);
                appInsightsLogger.LogRedisUpsert("Redis upsert failed.", redisOperation, DateTime.UtcNow.ToString(), update.ApiPath);
                return(new StatusCodeResult(500));
            }
        }
コード例 #2
0
        public void Test_Telemetry_LogMetricWithObject()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Information);

                // Act
                logger.LogMetric("test", 5, new Test
                {
                    PropA = "propA",
                    PropB = 1,
                    PropC = true,
                    PropD = new SubItem
                    {
                        PropE = "propE",
                        PropF = new List <int> {
                            1, 2, 3
                        }
                    }
                });
                logger.Flush();
            });
        }
コード例 #3
0
        public void Test_Telemetry_LogMetric()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogMetric("test", 3.1);
                logger.Flush();
            });
        }
コード例 #4
0
        public void Test_Telemetry_LogMetricWithProperties()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.Trace);

                // Act
                logger.LogMetric("test", 3.1, new Dictionary <string, string> {
                    { "a", "a" }, { "b", "b" }
                });
                logger.Flush();
            });
        }
コード例 #5
0
        public void Test_Telemetry_LogLevelNone()
        {
            // Assert
            AssertExtensions.DoesNotThrow(() =>
            {
                // Arrange
                var logger = new AppInsightsLogger("test", LogLevel.None);

                // Act
                logger.Log(LogLevel.Trace, new EventId(1, "test"), "test", null, null);
                logger.LogError(new Exception(), null, null, null, null);
                logger.LogMetric("test", Double.MinValue);
                logger.Log(LogLevel.Trace, new EventId(1, "test"), "test", null, null);
                logger.Flush();
            });
        }
コード例 #6
0
        private static void LogSetCount(string setName, APITask task, IDatabase db, AppInsightsLogger appInsightsLogger)
        {
            var len = db.SortedSetLength(setName);

            appInsightsLogger.LogMetric(setName, len, task.EndpointPath);
        }