예제 #1
0
        /// <summary>
        /// Ends metrics for a given service. This method also tracks the service status (any exceptions) and the number of items processed.
        /// </summary>
        /// <param name="methodName">Method Name</param>
        /// <param name="exception">Exception (if one occured)</param>
        /// <param name="itemsProcessed">Number of Items Processed</param>
        public void EndServiceCall(string methodName, Exception exception, string callingIPAddress = null)
        {
            DateTime timestamp = DateTime.Now;

            if (string.IsNullOrEmpty(callingIPAddress))
            {
                callingIPAddress = GetCallingIPAddress();
            }

            ServiceMetricStatusEnum status = ServiceMetricStatusEnum.Success;

            if (exception != null)
            {
                if (exception is APIException)
                {
                    status = ServiceMetricStatusEnum.Error;
                }
                else
                {
                    status = ServiceMetricStatusEnum.Exception;
                }
            }

            lock (CurrentWebMethodCallStart)
            {
                TimeSpan processTime = timestamp.Subtract(CurrentWebMethodCallStart[methodName]);
                CurrentServiceMetrics.EndServiceCall(methodName, status, processTime, timestamp, callingIPAddress, GetHostName(callingIPAddress));
            }
        }
예제 #2
0
        /// <summary>
        /// Starts metrics for a given service. Eg. Process Time and Active Requests.
        /// This method knows who calls it.
        /// <param name="webMethodName">Web Method Name</param>
        /// </summary>
        public void StartServiceCall(string webMethodName)
        {
            DateTime timestamp = DateTime.Now;

            lock (CurrentWebMethodCallStart)
            {
                if (!CurrentWebMethodCallStart.ContainsKey(webMethodName))
                {
                    CurrentWebMethodCallStart.Add(webMethodName, timestamp);
                }
                else
                {
                    CurrentWebMethodCallStart[webMethodName] = timestamp;
                }

                CurrentServiceMetrics.StartServiceCall(webMethodName);
            }
        }