Beispiel #1
0
        /// <summary>
        /// 记录监控接口执行日志
        /// </summary>
        /// <param name="actionExecutedContext"></param>
        /// <returns></returns>
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            DateTime requestTime = DateHelper.UnixStampToDateTme(Convert.ToInt64(actionExecutedContext.Request.Properties[RequestTimeKey]));
            string   requestId   = actionExecutedContext.Request.Properties[RequestKey].ToString();
            var      stopWatch   = actionExecutedContext.Request.Properties[Key] as Stopwatch;

            if (stopWatch != null)
            {
                stopWatch.Stop();
                var    actionName     = actionExecutedContext.ActionContext.ActionDescriptor.ActionName;
                var    controllerName = actionExecutedContext.ActionContext.ActionDescriptor.ControllerDescriptor.ControllerName;
                string log            = string.Format("Thread:{0}  {1}.{2}   Take {3} ms.", Thread.CurrentThread.ManagedThreadId, controllerName, actionName, stopWatch.Elapsed.TotalMilliseconds.ToString("0."));
                Trace.WriteLine(log);

                ThreadPool.QueueUserWorkItem(new WaitCallback((obj) =>
                {
                    SnakeWebApiHttpProxy snakeWebApiHttpProxy = new SnakeWebApiHttpProxy();
                    snakeWebApiHttpProxy.PublishTrackLog <string>(new TrackLogCreatedEvent()
                    {
                        RequestIP          = actionExecutedContext.Request.GetClientIpAddress(),
                        RequestId          = requestId,
                        RequestTime        = requestTime,
                        ResponseIPv4       = UrlHelper.GetIPv4(),
                        RequestPort        = actionExecutedContext.Request.RequestUri.Port,
                        RequestUrl         = actionExecutedContext.Request.RequestUri.OriginalString,
                        ResponseController = controllerName,
                        ResponseAction     = actionExecutedContext.ActionContext.ActionDescriptor.ActionName,
                        ExecutedTime       = stopWatch.Elapsed.TotalMilliseconds
                    });
                }));
            }
        }
Beispiel #2
0
        private async void OnTagIsDropDownOpenCommandExecute()
        {
            var dto = new QueryParamDto()
            {
                StrParam = ""
            };
            SnakeWebApiHttpProxy proxy = new SnakeWebApiHttpProxy();
            var result = await proxy.QueryTagsOfAppLogAsync <IList <string> >(dto);

            if (result.Item1 && result.Item2 != null)
            {
                Tags = new ObservableCollection <string>(result.Item2);
            }
        }
Beispiel #3
0
 private static void Log(string message, string application, int level, LogCategory logCategory, IList <string> tags)
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback((obj) =>
     {
         SnakeWebApiHttpProxy snakeWebApiHttpProxy = new SnakeWebApiHttpProxy();
         snakeWebApiHttpProxy.PublishAppLog <string>(new AppLogCreatedEvent()
         {
             Guid        = Guid.NewGuid().ToString(),
             CTime       = DateTime.Now,
             IPv4        = UrlHelper.GetIPv4(),
             Application = application,
             AppPath     = Process.GetCurrentProcess().MainModule.FileName,
             Machine     = Environment.MachineName,
             LogCategory = logCategory.ToString(),
             Message     = message,
             Level       = level,
             Tags        = tags
         });
     }));
 }
Beispiel #4
0
        private async void QueryAppLogsAsync()
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            SnakeWebApiHttpProxy proxy = new SnakeWebApiHttpProxy();
            var result = await proxy.GetAppLogsPageAsync <IList <AppLog> >(this.PageAppLog);

            stopWatch.Stop();
            if (result.Item1 && result.Item2 != null)
            {
                AppLogs = new ObservableCollection <AppLog>(result.Item2);
            }
            else
            {
                AppLogs = null;
            }
            string log = string.Format("AppLog数据:{0}条  查询用时:{1} ms.", AppLogs == null ? 0 : AppLogs.Count, stopWatch.Elapsed.TotalMilliseconds.ToString("0."));

            Messenger.Default.Send(new StatusUpdateMessage(log));
        }
Beispiel #5
0
        private async void OnQueryNextPageCommandExecute()
        {
            Status = ViewModelStatus.Loading;
            try
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                SnakeWebApiHttpProxy proxy = new SnakeWebApiHttpProxy();
                var result = await proxy.GetAppLogsPageAsync <IList <AppLog> >(this.PageAppLog);

                stopWatch.Stop();
                if (result.Item1 && result.Item2 != null)
                {
                    var list = AppLogs.Union <AppLog>(result.Item2).ToList <AppLog>();
                    AppLogs = new ObservableCollection <AppLog>(list);
                }
                string log = string.Format("AppLog数据:{0}条  用时:{1} ms.", AppLogs == null ? 0 : AppLogs.Count, stopWatch.Elapsed.TotalMilliseconds.ToString("0."));
                Messenger.Default.Send(new StatusUpdateMessage(log));
            }
            finally
            {
                Status = ViewModelStatus.Loaded;
            }
        }