예제 #1
0
        protected override void OnStop()
        {
            CDRLogger.Logger.LogInfo("OnStop()");

            if (receiveIndex != null)
            {
                receiveIndex.Stop();
                receiveIndex = null;
            }

            CDRLogger.Logger.LogInfo("KillAccountingThread();");
            KillAccountingThread();

            Webservice.ForceServiceOffline = true;

            // stop service code goes here
            base.OnStop();

            CDRLogger.Logger.LogInfo("serviceMutex.ReleaseMutex();");
            if (serviceMutex != null)
            {
                if (serviceMutex.WaitOne(TimeSpan.Zero, true))
                {
                    serviceMutex.ReleaseMutex();
                    serviceMutex = null;
                }
            }

            if (hostHealthService != null && hostHealthService.State == CommunicationState.Opened)
            {
                hostHealthService.Close(new TimeSpan(0, 0, 10)); // sluiten na max 10 seconden
            }
            if (host != null && host.State == CommunicationState.Opened)
            {
                host.Close(new TimeSpan(0, 0, 10)); // sluiten na max 10 seconden
            }

            CDRLogger.Logger.LogInfo("SMTPLogging.Close();");
            SMTPLogging.Close();
            CDRLogger.Logger.LogInfo("LogUsage.Close();");
            LogUsage.Close();
        }
예제 #2
0
 /// <summary>
 /// static constructor die private class initieert zodat destructor werkt (static destructor werkt blijkbaar niet)
 /// </summary>
 static LogUsage()
 {
     logRows    = new Queue <LogRow>();
     _singleton = new LogUsage();
 }
예제 #3
0
        /// <summary>
        /// Zie map ServiceLogging waar we "InspectorEventArgs" zelf maken en vullen!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LogReceivedRequest(object sender, InspectorEventArgs e)
        {
            double timeSpentInMS = (System.DateTime.Now - e.TimeStamp).TotalMilliseconds;

            bool slowLogEntry = false;
            // =================================================================================
            // Slow query logging mail code
            // =================================================================================
            double avgTimeSpent = CollectTimeSpanSpentInMethods(Convert.ToInt32(timeSpentInMS), e.FunctionName);

            if (avgTimeSpent >= 0 && (((avgTimeSpent * 2) < 1000 && timeSpentInMS > 1000) || ((avgTimeSpent * 2) > 1000 && timeSpentInMS > 10000)))
            {
                slowLogEntry = true;
                lock (slowQueryLog)
                {
                    if (slowQueryLog.NumberOfRows == 0)
                    {
                        slowQueryLog.NumberOfRows++;
                        slowQueryLog.FirstRowAdded = DateTime.Now;
                    }

                    // De functie doet er langer dan gemiddeld over! (zelf met 10% extra tijd die we hier rekenen)
                    slowQueryLog.Body.Append(e.TimeStamp.ToString("[dd/MMM/yyyy:HH:mm:ss zzz]", culture));
                    slowQueryLog.Body.Append(' ');
                    slowQueryLog.Body.Append(e.FunctionName + ": spent " + timeSpentInMS.ToString("0") + "ms while average is " + avgTimeSpent.ToString("0") + "\r\n");
                } //lock
            }

            // Detecteer of we de "slowQueryLog" moeten versturen. Doen we bij 100 berichten of na 5 minuten verzamelen
            lock (slowQueryLog)
            {
                if (slowQueryLog.NumberOfRows >= 200 || (slowQueryLog.NumberOfRows > 0 && (DateTime.Now.Date - slowQueryLog.FirstRowAdded.Date).TotalDays != 0))
                {
                    // verstuur log!
                    if (sendSlowLog)
                    {
                        SMTPLogging.AddSMTPMessage(string.Format("SlowQueryLog CDRWebService ({0})", Environment.MachineName), slowQueryLog.Body.ToString());
                    }
                    slowQueryLog.Body.Clear();
                    slowQueryLog.NumberOfRows = 0;
                }
            }
            // =================================================================================


            // Maak Apache a Like Log regel en schrijf deze weg
            StringBuilder sb = new StringBuilder(256);

            try
            {
                if (slowLogEntry)
                {
                    sb.Append("# Slow query\r\n");
                }
                sb.Append(e.TimeStamp.ToString("[dd/MMM/yyyy:HH:mm:ss zzz]", culture));
                sb.Append(' '); // seperator
                sb.Append(e.ClientIP);
                sb.Append(' '); // seperator
                sb.Append(e.Username);
                sb.Append(' '); // seperator
                sb.Append(e.Servername);
                sb.Append(' '); // seperator
                sb.Append(e.LocalIP);
                sb.Append(' '); // seperator

                // Extra info niet in normaal CDR apache log
                sb.Append(timeSpentInMS.ToString("0"));
                sb.Append("ms");
                sb.Append(' '); // seperator

                // POST of GET request info
                sb.Append('"');
                sb.Append(e.Method);
                sb.Append(' ');
                sb.Append(e.Request);
                sb.Append(" HTTP/1.0"); // faked
                sb.Append('"');
                sb.Append(' ');         // seperator

                if (e.FunctionName.Length <= 0)
                {
                    // Failed dus 404
                    sb.Append("404");
                }
                else
                {
                    // function exists dus 200
                    sb.Append("200");
                }
                sb.Append(' '); // seperator

                sb.Append(e.ResponseInBytes.ToString());
                sb.Append(' '); // seperator

                sb.Append('"');
                sb.Append(e.Referer);
                sb.Append('"');
                sb.Append(' '); // seperator

                sb.Append('"');
                sb.Append(e.Cookie);
                sb.Append('"');
            }
            catch
            {
                if (e != null && e.Message != null)
                {
                    sb.Append(e.Message);
                }
            }
            LogUsage.AddLog(sb.ToString());
        }