Exemplo n.º 1
0
        private void context_BeginRequestExecute(object sender, EventArgs e)
        {
            if (PageMonitorSettings.GetConfig().Enabled)
            {
                PageMonitorElement pme = PageMonitorSettings.GetConfig().Pages.GetMatchedElement();

                if (pme != null)
                {
                    MonitorData md = PerformanceMonitorHelper.StartMonitor(PageMonitorModule.MonitorDataKey);

                    md.EnableLogging   = pme.EnableLogging;
                    md.EnablePFCounter = pme.EnablePFCounter;
                    md.MonitorName     = pme.Name;

                    if (string.IsNullOrEmpty(pme.CounterInstanceName))
                    {
                        md.InstanceName = pme.Name;
                    }
                    else
                    {
                        md.InstanceName = pme.CounterInstanceName;
                    }

                    PerformanceMonitorHelper.DefaultMonitorName = PageMonitorModule.MonitorDataKey;

                    if (pme.EnableLogging)
                    {
                        md.LogWriter.WriteLine("请求{0}的开始时间: {1:yyyy-MM-dd HH:mm:ss.fff}", md.MonitorName, SNTPClient.AdjustedTime);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private object InvokeWithMonitor(object instance, object[] inputs, out object[] outputs)
        {
            ServiceMethodConfigurationElement methodElement = ServiceSettings.GetConfig().GetMethodElementByOperationContext();

            object[] result = null;

            if (methodElement != null)
            {
                PerformanceMonitorHelper.DefaultMonitorName = MonitorName;
                MonitorData md = PerformanceMonitorHelper.StartMonitor(MonitorName);

                md.MonitorName     = string.Format("{0}.{1}", OperationContext.Current.GetContractName(), OperationContext.Current.GetMethodName());
                md.EnableLogging   = methodElement.EnableLogging;
                md.EnablePFCounter = methodElement.EnablePFCounter;

                md.InstanceName = md.MonitorName;
                md.Context["GlobalInstance"] = new WebMethodServerCounters("_Total_");
                md.Context["Instance"]       = new WebMethodServerCounters(md.InstanceName);

                if (md.EnableLogging)
                {
                    md.LogWriter.WriteLine("请求{0}的开始时间: {1:yyyy-MM-dd HH:mm:ss.fff}", md.MonitorName, SNTPClient.AdjustedTime);
                }

                try
                {
                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(md.MonitorName,
                                                                                        () =>
                    {
                        result = this.InternalInvoke(instance, inputs);
                    });
                }
                catch (System.Exception ex)
                {
                    md.HasErrors = true;

                    if (md.EnableLogging)
                    {
                        ex.WriteToEventLog(md.MonitorName, EventLogEntryType.Error, 8010);
                    }

                    throw;
                }
                finally
                {
                    CommitMonitorData();
                }
            }
            else
            {
                result = this.InternalInvoke(instance, inputs);
            }

            outputs = (object[])result[1];

            return(result[0]);
        }