private void FillBasicWmiDataFields(ref UnsafeNativeMethods.WmiData wmiData, WebBaseEvent eventRaised)
        {
            WebApplicationInformation applicationInformation = WebBaseEvent.ApplicationInformation;

            wmiData.eventType       = (int)WebBaseEvent.WebEventTypeFromWebEvent(eventRaised);
            wmiData.eventCode       = eventRaised.EventCode;
            wmiData.eventDetailCode = eventRaised.EventDetailCode;
            wmiData.eventTime       = this.WmiFormatTime(eventRaised.EventTime);
            wmiData.eventMessage    = eventRaised.Message;
            wmiData.sequenceNumber  = eventRaised.EventSequence.ToString(CultureInfo.InstalledUICulture);
            wmiData.occurrence      = eventRaised.EventOccurrence.ToString(CultureInfo.InstalledUICulture);
            wmiData.eventId         = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture);
            wmiData.appDomain       = applicationInformation.ApplicationDomain;
            wmiData.trustLevel      = applicationInformation.TrustLevel;
            wmiData.appVirtualPath  = applicationInformation.ApplicationVirtualPath;
            wmiData.appPath         = applicationInformation.ApplicationPath;
            wmiData.machineName     = applicationInformation.MachineName;
            if (eventRaised.IsSystemEvent)
            {
                wmiData.details = string.Empty;
            }
            else
            {
                WebEventFormatter formatter = new WebEventFormatter();
                eventRaised.FormatCustomEventDetails(formatter);
                wmiData.details = formatter.ToString();
            }
        }
        public override void ProcessEvent(WebBaseEvent raisedEvent)
        {
            var repo = DependencyResolver.Current.GetService<IService<Log>>();

            var applicationInformation = WebBaseEvent.ApplicationInformation;

            var log = new Log
            {
                EventCode = raisedEvent.EventCode,
                EventType = raisedEvent.GetType().ToString(),
                EventSequence = raisedEvent.EventSequence,
                EventOccurrence = raisedEvent.EventOccurrence,
                Message = raisedEvent.Message,
                EventDetailCode = raisedEvent.EventDetailCode,
                ApplicationPath = applicationInformation.ApplicationPath,
                ApplicationVirtualPath = applicationInformation.ApplicationVirtualPath,
                MachineName = applicationInformation.MachineName
            };

            if (raisedEvent is IUserInfoEvent)
            {
                log.Username = (raisedEvent as IUserInfoEvent).Username;
                log.Tenant = (raisedEvent as IUserInfoEvent).Tenant;
            }

            repo.SaveOrUpdate(log);
        }
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     HttpContext context = HttpContext.Current;
     if (context != null) {
         context.WorkerRequest.RaiseTraceEvent(eventRaised);
     }
 }
Exemplo n.º 4
0
        internal string GenerateSubject(int notificationSequence, int messageSequence, WebBaseEventCollection events, int count)
        {
            WebBaseEvent eventRaised = events[0];

            if (count == 1)
            {
                return(HttpUtility.HtmlEncode(SR.GetString(SR.WebEvent_event_email_subject,
                                                           new string[] {
                    notificationSequence.ToString(CultureInfo.InstalledUICulture),
                    messageSequence.ToString(CultureInfo.InstalledUICulture),
                    _subjectPrefix,
                    eventRaised.GetType().ToString(),
                    WebBaseEvent.ApplicationInformation.ApplicationVirtualPath
                }
                                                           )));
            }
            else
            {
                return(HttpUtility.HtmlEncode(SR.GetString(SR.WebEvent_event_group_email_subject,
                                                           new string[] {
                    notificationSequence.ToString(CultureInfo.InstalledUICulture),
                    messageSequence.ToString(CultureInfo.InstalledUICulture),
                    _subjectPrefix,
                    count.ToString(CultureInfo.InstalledUICulture),
                    WebBaseEvent.ApplicationInformation.ApplicationVirtualPath
                }
                                                           )));
            }
        }
        internal override void SendMessage(WebBaseEvent eventRaised)
        {
            bool flag;
            WebBaseEventCollection events = new WebBaseEventCollection(eventRaised);

            this.SendMessageInternal(events, DateTime.MinValue, 0, 0, Interlocked.Increment(ref this._nonBufferNotificationSequence), EventNotificationType.Unbuffered, 1, 0, 1, 0, 1, out flag);
        }
        public void FormatToString(WebEventFormatter formatter)
        {
            string name;
            string authenticationType;
            bool   isAuthenticated;

            if (this.Principal == null)
            {
                name = string.Empty;
                authenticationType = string.Empty;
                isAuthenticated    = false;
            }
            else
            {
                IIdentity identity = this.Principal.Identity;
                name               = identity.Name;
                isAuthenticated    = identity.IsAuthenticated;
                authenticationType = identity.AuthenticationType;
            }
            formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_request_url", this.RequestUrl));
            formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_request_path", this.RequestPath));
            formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_user_host_address", this.UserHostAddress));
            formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_user", name));
            if (isAuthenticated)
            {
                formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_is_authenticated"));
            }
            else
            {
                formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_is_not_authenticated"));
            }
            formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_authentication_type", authenticationType));
            formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_thread_account_name", this.ThreadAccountName));
        }
        internal void AddEvent(WebBaseEvent webEvent)
        {
            lock (_buffer) {
#if DBG
                _totalAdded++;
#endif
                // If we have filled up the buffer, remove items using FIFO order.
                if (_buffer.Count == _maxBufferSize)
                {
                    Debug.Trace("WebEventBuffer", "Buffer is full.  Need to remove one from the tail");
                    _buffer.Dequeue();
                    _discardedSinceLastFlush++;
#if DBG
                    _totalAbandoned++;
#endif
                }

                _buffer.Enqueue(webEvent);

                // If we have at least _urgentFlushThreshold, flush.  Please note the flush is async.
                if (_buffer.Count >= _urgentFlushThreshold)
                {
                    Flush(_maxFlushSize, FlushCallReason.UrgentFlushThresholdExceeded);
                }

                // Note that Flush uses _lastAdd, which is the time an event (not including this one)
                // was last added.  That's why we call it after calling Flush.
                _lastAdd = DateTime.UtcNow;
            }   // Release the lock
        }
Exemplo n.º 8
0
 internal override void FormatToString(WebEventFormatter formatter, bool includeAppInfo)
 {
     base.FormatToString(formatter, includeAppInfo);
     if (this._exception != null)
     {
         Exception innerException = this._exception;
         for (int i = 0; (innerException != null) && (i <= 2); i++)
         {
             formatter.AppendLine(string.Empty);
             if (i == 0)
             {
                 formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_exception_information"));
             }
             else
             {
                 formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_inner_exception_information", i.ToString(CultureInfo.InstalledUICulture)));
             }
             formatter.IndentationLevel++;
             formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_exception_type", innerException.GetType().ToString()));
             formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_exception_message", innerException.Message));
             formatter.IndentationLevel--;
             innerException = innerException.InnerException;
         }
     }
 }
Exemplo n.º 9
0
        // <Snippet22>
        // Implements the IWebEventCustomEvaluator.CanFire
        // method. It is called by the ASP.NET if this custom
        // type is configured in the profile
        // element of the healthMonitoring section.
        public bool CanFire(
            System.Web.Management.WebBaseEvent e,
            RuleFiringRecord rule)
        {
            bool   fireEvent;
            string lastFired   = rule.LastFired.ToString();
            string timesRaised = rule.TimesRaised.ToString();

            // Fire every other event raised.
            fireEvent =
                (rule.TimesRaised % 2 == 0) ? true : false;

            if (fireEvent)
            {
                firingRecordInfo =
                    string.Format("Event last fired: {0}",
                                  lastFired) +
                    string.Format(". Times raised: {0}",
                                  timesRaised);
            }
            else
            {
                firingRecordInfo =
                    string.Format(
                        "Event not fired. Times raised: {0}",
                        timesRaised);
            }

            return(fireEvent);
        }
Exemplo n.º 10
0
        private void AddBasicDataFields(ArrayList dataFields, WebBaseEvent eventRaised)
        {
            WebApplicationInformation applicationInformation = WebBaseEvent.ApplicationInformation;

            dataFields.Add(eventRaised.EventCode.ToString(CultureInfo.InstalledUICulture));
            dataFields.Add(eventRaised.Message);
            dataFields.Add(eventRaised.EventTime.ToString());
            dataFields.Add(eventRaised.EventTimeUtc.ToString());
            dataFields.Add(eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture));
            dataFields.Add(eventRaised.EventSequence.ToString(CultureInfo.InstalledUICulture));
            dataFields.Add(eventRaised.EventOccurrence.ToString(CultureInfo.InstalledUICulture));
            dataFields.Add(eventRaised.EventDetailCode.ToString(CultureInfo.InstalledUICulture));
            dataFields.Add(applicationInformation.ApplicationDomain);
            dataFields.Add(applicationInformation.TrustLevel);
            dataFields.Add(applicationInformation.ApplicationVirtualPath);
            dataFields.Add(applicationInformation.ApplicationPath);
            dataFields.Add(applicationInformation.MachineName);
            if (eventRaised.IsSystemEvent)
            {
                dataFields.Add(null);
            }
            else
            {
                WebEventFormatter formatter = new WebEventFormatter();
                eventRaised.FormatCustomEventDetails(formatter);
                dataFields.Add(formatter.ToString());
            }
        }
 private void AddBasicDataFields(ArrayList dataFields, WebBaseEvent eventRaised)
 {
     WebApplicationInformation applicationInformation = WebBaseEvent.ApplicationInformation;
     dataFields.Add(eventRaised.EventCode.ToString(CultureInfo.InstalledUICulture));
     dataFields.Add(eventRaised.Message);
     dataFields.Add(eventRaised.EventTime.ToString());
     dataFields.Add(eventRaised.EventTimeUtc.ToString());
     dataFields.Add(eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture));
     dataFields.Add(eventRaised.EventSequence.ToString(CultureInfo.InstalledUICulture));
     dataFields.Add(eventRaised.EventOccurrence.ToString(CultureInfo.InstalledUICulture));
     dataFields.Add(eventRaised.EventDetailCode.ToString(CultureInfo.InstalledUICulture));
     dataFields.Add(applicationInformation.ApplicationDomain);
     dataFields.Add(applicationInformation.TrustLevel);
     dataFields.Add(applicationInformation.ApplicationVirtualPath);
     dataFields.Add(applicationInformation.ApplicationPath);
     dataFields.Add(applicationInformation.MachineName);
     if (eventRaised.IsSystemEvent)
     {
         dataFields.Add(null);
     }
     else
     {
         WebEventFormatter formatter = new WebEventFormatter();
         eventRaised.FormatCustomEventDetails(formatter);
         dataFields.Add(formatter.ToString());
     }
 }
Exemplo n.º 12
0
        void FillBasicWmiDataFields(ref UnsafeNativeMethods.WmiData wmiData, WebBaseEvent eventRaised) {
            WebApplicationInformation       appInfo = WebBaseEvent.ApplicationInformation;
            
            wmiData.eventType = (int)WebBaseEvent.WebEventTypeFromWebEvent(eventRaised);

            // Note: WMI sint64 requires a string param
            
            // Data contained in WebBaseEvent
            wmiData.eventCode = eventRaised.EventCode;
            wmiData.eventDetailCode = eventRaised.EventDetailCode;
            wmiData.eventTime = WmiFormatTime(eventRaised.EventTime);
            wmiData.eventMessage = eventRaised.Message;
            wmiData.sequenceNumber = eventRaised.EventSequence.ToString(CultureInfo.InstalledUICulture);   
            wmiData.occurrence = eventRaised.EventOccurrence.ToString(CultureInfo.InstalledUICulture);   
            wmiData.eventId = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture);   
        
            wmiData.appDomain = appInfo.ApplicationDomain;
            wmiData.trustLevel = appInfo.TrustLevel;
            wmiData.appVirtualPath = appInfo.ApplicationVirtualPath;
            wmiData.appPath = appInfo.ApplicationPath;
            wmiData.machineName = appInfo.MachineName;

            if (eventRaised.IsSystemEvent) {
                wmiData.details = String.Empty;
            }
            else {
                WebEventFormatter   formatter = new WebEventFormatter();
                eventRaised.FormatCustomEventDetails(formatter);
                wmiData.details = formatter.ToString();
            }
        }
Exemplo n.º 13
0
        public static WebEvent FromWebBaseEvent(WebBaseEvent webBaseEvent)
        {
          var webEvent = new WebEvent
          {
            ApplicationPath = HostingEnvironment.ApplicationPhysicalPath,
            ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath,
            Details = webBaseEvent.ToString(),
            EventCode = webBaseEvent.EventCode,
            EventDetailCode = webBaseEvent.EventDetailCode,
            EventID = webBaseEvent.EventID,
            EventOccurrence = webBaseEvent.EventOccurrence,
            EventSequence = webBaseEvent.EventSequence,
            EventTime = webBaseEvent.EventTime,
            EventTimeUtc = webBaseEvent.EventTimeUtc,
            EventType = webBaseEvent.GetType().Name,
            Message = webBaseEvent.Message
          };


          var baseErrorEvent = webBaseEvent as WebBaseErrorEvent;
          if (baseErrorEvent != null)
            {
                webEvent.ExceptionType = baseErrorEvent.ErrorException.GetType().Name;
            }

            return webEvent;
        }
Exemplo n.º 14
0
        //public string RequestUrl { get; set; }

        public static WebEvent FromWebBaseEvent(WebBaseEvent webBaseEvent)
        {
            var webEvent = new WebEvent();

            webEvent.ApplicationPath = HostingEnvironment.ApplicationPhysicalPath;
            webEvent.ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath;
            webEvent.Details = webBaseEvent.ToString();
            webEvent.EventCode = webBaseEvent.EventCode;
            webEvent.EventDetailCode = webBaseEvent.EventDetailCode;
            webEvent.EventID = webBaseEvent.EventID;
            webEvent.EventOccurrence = webBaseEvent.EventOccurrence;
            webEvent.EventSequence = webBaseEvent.EventSequence;
            webEvent.EventTime = webBaseEvent.EventTime;
            webEvent.EventTimeUtc = webBaseEvent.EventTimeUtc;
            webEvent.EventType = webBaseEvent.GetType().Name;
            //webEvent.MachineName = HttpContext.Current.Server.MachineName;
            webEvent.Message = webBaseEvent.Message;
            //webEvent.RequestUrl = HttpContext.Current.Request.Url.ToString();

            if (webBaseEvent is WebBaseErrorEvent)
            {
                webEvent.ExceptionType = ((WebBaseErrorEvent)webBaseEvent).ErrorException.GetType().Name;
            }

            return webEvent;
        }
 public void FormatToString(WebEventFormatter formatter)
 {
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_application_domain", this.ApplicationDomain));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_trust_level", this.TrustLevel));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_application_virtual_path", this.ApplicationVirtualPath));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_application_path", this.ApplicationPath));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_machine_name", this.MachineName));
 }
Exemplo n.º 16
0
 internal WebBaseEventCollection(WebBaseEvent eventRaised)
 {
     if (eventRaised == null)
     {
         throw new ArgumentNullException("eventRaised");
     }
     base.InnerList.Add(eventRaised);
 }
 internal WebBaseEventCollection(WebBaseEvent eventRaised)
 {
     if (eventRaised == null)
     {
         throw new ArgumentNullException("eventRaised");
     }
     base.InnerList.Add(eventRaised);
 }
        string GenerateBody(WebBaseEventCollection events,
                            int begin,
                            DateTime lastFlush,
                            int discardedSinceLastFlush,
                            int eventsInBuffer,
                            int messageSequence,
                            int eventsInNotification,
                            int eventsLostDueToMessageLimit)
        {
            StringBuilder sb          = new StringBuilder();
            int           totalEvents = events.Count;

            if (_bodyHeader != null)
            {
                sb.Append(_bodyHeader);
            }

            // Warnings
            GenerateWarnings(sb, lastFlush, discardedSinceLastFlush, messageSequence, eventsLostDueToMessageLimit);

            // Event Summary
            GenerateSummary(sb, begin, begin + totalEvents - 1, eventsInNotification, eventsInBuffer);

            // Application Info
            Debug.Assert(events.Count > 0, "events.Count > 0");
            GenerateApplicationInformation(sb);

            // Please note that it's a text message, and thus we shouldn't need to HtmlEncode it.
            for (int i = 0; i < totalEvents; i++)
            {
                WebBaseEvent eventRaised = events[i];
                string       details     = eventRaised.ToString(false, true);

                if (_maxEventLength != ProviderUtil.Infinite &&
                    details.Length > _maxEventLength)
                {
                    details = details.Substring(0, _maxEventLength);
                }

                if (i == 0)
                {
                    sb.Append(s_header_events);
                    sb.Append("\n");
                    sb.Append(_separator);
                }

                sb.Append(details);
                sb.Append("\n");
                sb.Append(_separator);
            }

            if (_bodyFooter != null)
            {
                sb.Append(_bodyFooter);
            }

            return(sb.ToString());
        }
Exemplo n.º 19
0
        void FillParams(SqlCommand sqlCommand, WebBaseEvent eventRaised)
        {
            Exception             exception = null;
            WebRequestInformation reqInfo   = null;
            string details = null;
            WebApplicationInformation appInfo = WebBaseEvent.ApplicationInformation;
            int n = 0;

            sqlCommand.Parameters[n++].Value = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture); // @EventId
            sqlCommand.Parameters[n++].Value = eventRaised.EventTimeUtc;                                          // @EventTimeUtc
            sqlCommand.Parameters[n++].Value = eventRaised.EventTime;                                             // @EventTime
            sqlCommand.Parameters[n++].Value = eventRaised.GetType().ToString();                                  // @EventType
            sqlCommand.Parameters[n++].Value = eventRaised.EventSequence;                                         // @EventSequence
            sqlCommand.Parameters[n++].Value = eventRaised.EventOccurrence;                                       // @EventOccurrence
            sqlCommand.Parameters[n++].Value = eventRaised.EventCode;                                             // @EventCode
            sqlCommand.Parameters[n++].Value = eventRaised.EventDetailCode;                                       // @EventDetailCode
            sqlCommand.Parameters[n++].Value = eventRaised.Message;                                               // @Message
            sqlCommand.Parameters[n++].Value = appInfo.ApplicationPath;                                           // @ApplicationPath
            sqlCommand.Parameters[n++].Value = appInfo.ApplicationVirtualPath;                                    // @ApplicationVirtualPath
            sqlCommand.Parameters[n++].Value = appInfo.MachineName;                                               // @MachineName

            //

            // @RequestUrl
            if (eventRaised is WebRequestEvent)
            {
                reqInfo = ((WebRequestEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebRequestErrorEvent)
            {
                reqInfo = ((WebRequestErrorEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebErrorEvent)
            {
                reqInfo = ((WebErrorEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebAuditEvent)
            {
                reqInfo = ((WebAuditEvent)eventRaised).RequestInformation;
            }
            sqlCommand.Parameters[n++].Value = (reqInfo != null) ? reqInfo.RequestUrl : Convert.DBNull;

            // @ExceptionType
            if (eventRaised is WebBaseErrorEvent)
            {
                exception = ((WebBaseErrorEvent)eventRaised).ErrorException;
            }
            sqlCommand.Parameters[n++].Value = (exception != null) ? exception.GetType().ToString() : Convert.DBNull;

            // @Details
            details = eventRaised.ToString();
            if (_maxEventDetailsLength != NO_LIMIT &&
                details.Length > _maxEventDetailsLength)
            {
                details = details.Substring(0, _maxEventDetailsLength);
            }
            sqlCommand.Parameters[n++].Value = details;
        }
Exemplo n.º 20
0
        public override void ProcessEvent(WebBaseEvent eventRaised)
        {
            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                context.WorkerRequest.RaiseTraceEvent(eventRaised);
            }
        }
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     if (eventRaised is WebBaseErrorEvent) {
         System.Diagnostics.Trace.TraceError(eventRaised.ToString());
     }
     else {
         System.Diagnostics.Trace.TraceInformation(eventRaised.ToString());
     }
 }
 private void WriteToSQL(WebBaseEventCollection events, int eventsDiscardedByBuffer, DateTime lastNotificationUtc)
 {
     if (this._retryDate <= DateTime.UtcNow)
     {
         try
         {
             SqlConnectionHolder connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
             SqlCommand          sqlCommand = new SqlCommand("dbo.aspnet_WebEvent_LogEvent");
             this.CheckSchemaVersion(connection.Connection);
             sqlCommand.CommandType = CommandType.StoredProcedure;
             sqlCommand.Connection  = connection.Connection;
             if (this._commandTimeout > -1)
             {
                 sqlCommand.CommandTimeout = this._commandTimeout;
             }
             this.PrepareParams(sqlCommand);
             try
             {
                 connection.Open(null, true);
                 Interlocked.Increment(ref this._connectionCount);
                 if (eventsDiscardedByBuffer != 0)
                 {
                     WebBaseEvent eventRaised = new WebBaseEvent(System.Web.SR.GetString("Sql_webevent_provider_events_dropped", new object[] { eventsDiscardedByBuffer.ToString(CultureInfo.InstalledUICulture), lastNotificationUtc.ToString("r", CultureInfo.InstalledUICulture) }), null, 0x1771, 0xc47d);
                     this.FillParams(sqlCommand, eventRaised);
                     sqlCommand.ExecuteNonQuery();
                 }
                 foreach (WebBaseEvent event3 in events)
                 {
                     this.FillParams(sqlCommand, event3);
                     sqlCommand.ExecuteNonQuery();
                 }
             }
             finally
             {
                 connection.Close();
                 Interlocked.Decrement(ref this._connectionCount);
             }
             try
             {
                 this.EventProcessingComplete(events);
             }
             catch
             {
             }
         }
         catch
         {
             double num = 30.0;
             if (this._commandTimeout > -1)
             {
                 num = this._commandTimeout;
             }
             this._retryDate = DateTime.UtcNow.AddSeconds(num);
             throw;
         }
     }
 }
Exemplo n.º 23
0
 internal override void FormatToString(WebEventFormatter formatter, bool includeAppInfo)
 {
     base.FormatToString(formatter, includeAppInfo);
     formatter.AppendLine(string.Empty);
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_process_statistics"));
     formatter.IndentationLevel++;
     s_procStats.FormatToString(formatter);
     formatter.IndentationLevel--;
 }
Exemplo n.º 24
0
 internal override void FormatToString(WebEventFormatter formatter, bool includeAppInfo)
 {
     base.FormatToString(formatter, includeAppInfo);
     formatter.AppendLine(string.Empty);
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_request_information"));
     formatter.IndentationLevel++;
     this.RequestInformation.FormatToString(formatter);
     formatter.IndentationLevel--;
 }
 internal override void FormatToString(WebEventFormatter formatter, bool includeAppInfo)
 {
     base.FormatToString(formatter, includeAppInfo);
     formatter.AppendLine(string.Empty);
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_ViewStateException_information"));
     formatter.IndentationLevel++;
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_exception_message", this._viewStateException.Message));
     formatter.IndentationLevel--;
 }
Exemplo n.º 26
0
 internal static WebEventType WebEventTypeFromWebEvent(WebBaseEvent eventRaised)
 {
     if (eventRaised is WebAuthenticationSuccessAuditEvent)
     {
         return(WebEventType.WEBEVENT_AUTHENTICATION_SUCCESS_AUDIT_EVENT);
     }
     if (eventRaised is WebAuthenticationFailureAuditEvent)
     {
         return(WebEventType.WEBEVENT_AUTHENTICATION_FAILURE_AUDIT_EVENT);
     }
     if (eventRaised is WebViewStateFailureAuditEvent)
     {
         return(WebEventType.WEBEVENT_VIEWSTATE_FAILURE_AUDIT_EVENT);
     }
     if (eventRaised is WebRequestErrorEvent)
     {
         return(WebEventType.WEBEVENT_REQUEST_ERROR_EVENT);
     }
     if (eventRaised is WebErrorEvent)
     {
         return(WebEventType.WEBEVENT_ERROR_EVENT);
     }
     if (eventRaised is WebSuccessAuditEvent)
     {
         return(WebEventType.WEBEVENT_SUCCESS_AUDIT_EVENT);
     }
     if (eventRaised is WebFailureAuditEvent)
     {
         return(WebEventType.WEBEVENT_FAILURE_AUDIT_EVENT);
     }
     if (eventRaised is WebHeartbeatEvent)
     {
         return(WebEventType.WEBEVENT_HEARTBEAT_EVENT);
     }
     if (eventRaised is WebApplicationLifetimeEvent)
     {
         return(WebEventType.WEBEVENT_APP_LIFETIME_EVENT);
     }
     if (eventRaised is WebRequestEvent)
     {
         return(WebEventType.WEBEVENT_REQUEST_EVENT);
     }
     if (eventRaised is WebBaseErrorEvent)
     {
         return(WebEventType.WEBEVENT_BASE_ERROR_EVENT);
     }
     if (eventRaised is WebAuditEvent)
     {
         return(WebEventType.WEBEVENT_AUDIT_EVENT);
     }
     if (eventRaised is WebManagementEvent)
     {
         return(WebEventType.WEBEVENT_MANAGEMENT_EVENT);
     }
     return(WebEventType.WEBEVENT_BASE_EVENT);
 }
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     if (base.UseBuffering)
     {
         base.ProcessEvent(eventRaised);
     }
     else
     {
         this.SendMessage(eventRaised);
     }
 }
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     if (base.UseBuffering)
     {
         base.ProcessEvent(eventRaised);
     }
     else
     {
         this.SendMessage(eventRaised);
     }
 }
Exemplo n.º 29
0
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     if (eventRaised is WebBaseErrorEvent)
     {
         System.Diagnostics.Trace.TraceError(eventRaised.ToString());
     }
     else
     {
         System.Diagnostics.Trace.TraceInformation(eventRaised.ToString());
     }
 }
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     if (base.UseBuffering)
     {
         base.ProcessEvent(eventRaised);
     }
     else
     {
         this.WriteToSQL(new WebBaseEventCollection(eventRaised), 0, new DateTime(0L));
     }
 }
Exemplo n.º 31
0
 public static void Raise(WebBaseEvent eventRaised)
 {
     if (eventRaised.EventCode < 0x186a0)
     {
         object[] args = new object[] { eventRaised.EventCode.ToString(CultureInfo.CurrentCulture), 0x186a0.ToString(CultureInfo.CurrentCulture) };
         throw new HttpException(System.Web.SR.GetString("System_eventCode_not_allowed", args));
     }
     if (HealthMonitoringManager.Enabled)
     {
         RaiseInternal(eventRaised, null, -1, -1);
     }
 }
Exemplo n.º 32
0
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     if (UseBuffering)
     {
         base.ProcessEvent(eventRaised);
     }
     else
     {
         Debug.Trace("SqlWebEventProvider", "Writing event to SQL: event=" + eventRaised.GetType().Name);
         WriteToSQL(new WebBaseEventCollection(eventRaised), 0, new DateTime(0));
     }
 }
        internal bool CheckAndUpdate(WebBaseEvent eventRaised)
        {
            DateTime now = DateTime.Now;
            HealthMonitoringManager manager = HealthMonitoringManager.Manager();
            int num = Interlocked.Increment(ref this._timesRaised);

            if (manager == null)
            {
                return(false);
            }
            if (this._ruleInfo._customEvaluatorType != null)
            {
                IWebEventCustomEvaluator evaluator = (IWebEventCustomEvaluator)manager._sectionHelper._customEvaluatorInstances[this._ruleInfo._customEvaluatorType];
                try
                {
                    eventRaised.PreProcessEventInit();
                    if (!evaluator.CanFire(eventRaised, this))
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            if (num < this._ruleInfo._minInstances)
            {
                return(false);
            }
            if (num > this._ruleInfo._maxLimit)
            {
                return(false);
            }
            if (this._ruleInfo._minInterval == TimeSpan.Zero)
            {
                this.UpdateLastFired(now, false);
                return(true);
            }
            if ((now - this._lastFired) <= this._ruleInfo._minInterval)
            {
                return(false);
            }
            lock (this)
            {
                if ((now - this._lastFired) <= this._ruleInfo._minInterval)
                {
                    return(false);
                }
                this.UpdateLastFired(now, true);
                return(true);
            }
        }
 public virtual void FormatToString(WebEventFormatter formatter)
 {
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_process_start_time", this.ProcessStartTime.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_thread_count", this.ThreadCount.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_working_set", this.WorkingSet.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_peak_working_set", this.PeakWorkingSet.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_managed_heap_size", this.ManagedHeapSize.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_application_domain_count", this.AppDomainCount.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_requests_executing", this.RequestsExecuting.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_request_queued", this.RequestsQueued.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_request_rejected", this.RequestsRejected.ToString(CultureInfo.InstalledUICulture)));
 }
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     if (this._buffer)
     {
         this._webEventBuffer.AddEvent(eventRaised);
     }
     else
     {
         WebEventBufferFlushInfo flushInfo = new WebEventBufferFlushInfo(new WebBaseEventCollection(eventRaised), EventNotificationType.Unbuffered, 0, DateTime.MinValue, 0, 0);
         this.ProcessEventFlush(flushInfo);
     }
 }
 internal bool CheckAndUpdate(WebBaseEvent eventRaised)
 {
     DateTime now = DateTime.Now;
     HealthMonitoringManager manager = HealthMonitoringManager.Manager();
     int num = Interlocked.Increment(ref this._timesRaised);
     if (manager == null)
     {
         return false;
     }
     if (this._ruleInfo._customEvaluatorType != null)
     {
         IWebEventCustomEvaluator evaluator = (IWebEventCustomEvaluator) manager._sectionHelper._customEvaluatorInstances[this._ruleInfo._customEvaluatorType];
         try
         {
             eventRaised.PreProcessEventInit();
             if (!evaluator.CanFire(eventRaised, this))
             {
                 return false;
             }
         }
         catch
         {
             return false;
         }
     }
     if (num < this._ruleInfo._minInstances)
     {
         return false;
     }
     if (num > this._ruleInfo._maxLimit)
     {
         return false;
     }
     if (this._ruleInfo._minInterval == TimeSpan.Zero)
     {
         this.UpdateLastFired(now, false);
         return true;
     }
     if ((now - this._lastFired) <= this._ruleInfo._minInterval)
     {
         return false;
     }
     lock (this)
     {
         if ((now - this._lastFired) <= this._ruleInfo._minInterval)
         {
             return false;
         }
         this.UpdateLastFired(now, true);
         return true;
     }
 }
Exemplo n.º 37
0
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     Debug.Trace("MailWebEventProvider", "ProcessEvent: type =" + eventRaised.GetType() +
                 ", ID=" + eventRaised.EventID + ", buffer=" + UseBuffering);
     if (UseBuffering)
     {
         base.ProcessEvent(eventRaised);
     }
     else
     {
         SendMessage(eventRaised);
     }
 }
 internal override void RaiseTraceEvent(WebBaseEvent webEvent)
 {
     if ((IntPtr.Zero != base._ecb) && EtwTrace.IsTraceEnabled(webEvent.InferEtwTraceVerbosity(), 1))
     {
         int num;
         string[] strArray;
         int[] numArray;
         string[] strArray2;
         int num2;
         webEvent.DeconstructWebEvent(out num2, out num, out strArray, out numArray, out strArray2);
         UnsafeNativeMethods.EcbEmitWebEventTrace(base._ecb, num2, num, strArray, numArray, strArray2);
     }
 }
Exemplo n.º 39
0
 public void FormatToString(WebEventFormatter formatter)
 {
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_thread_id", this.ThreadID.ToString(CultureInfo.InstalledUICulture)));
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_thread_account_name", this.ThreadAccountName));
     if (this.IsImpersonating)
     {
         formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_is_impersonating"));
     }
     else
     {
         formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_is_not_impersonating"));
     }
     formatter.AppendLine(WebBaseEvent.FormatResourceStringWithCache("Webevent_event_stack_trace", this.StackTrace));
 }
        // Processes the incoming events.
        // This method performs custom processing and, if
        // buffering is enabled, it calls the base.ProcessEvent
        // to buffer the event information.
        public override void ProcessEvent(WebBaseEvent eventRaised)
        {
            if (UseBuffering)
                base.ProcessEvent(eventRaised);
            else
            {
                // Buffering disabled, store event info
                // immediately.
                customInfo.AppendLine(string.Format("{0}", eventRaised.Message));

                // Store the information in the specified file.
                StoreToFile(customInfo, connectionString, FileMode.Append);
            }
        }
        private void FillParams(SqlCommand sqlCommand, WebBaseEvent eventRaised)
        {
            Exception             errorException     = null;
            WebRequestInformation requestInformation = null;
            string str = null;
            WebApplicationInformation applicationInformation = WebBaseEvent.ApplicationInformation;
            int num = 0;

            sqlCommand.Parameters[num++].Value = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture);
            sqlCommand.Parameters[num++].Value = eventRaised.EventTimeUtc;
            sqlCommand.Parameters[num++].Value = eventRaised.EventTime;
            sqlCommand.Parameters[num++].Value = eventRaised.GetType().ToString();
            sqlCommand.Parameters[num++].Value = eventRaised.EventSequence;
            sqlCommand.Parameters[num++].Value = eventRaised.EventOccurrence;
            sqlCommand.Parameters[num++].Value = eventRaised.EventCode;
            sqlCommand.Parameters[num++].Value = eventRaised.EventDetailCode;
            sqlCommand.Parameters[num++].Value = eventRaised.Message;
            sqlCommand.Parameters[num++].Value = applicationInformation.ApplicationPath;
            sqlCommand.Parameters[num++].Value = applicationInformation.ApplicationVirtualPath;
            sqlCommand.Parameters[num++].Value = applicationInformation.MachineName;
            if (eventRaised is WebRequestEvent)
            {
                requestInformation = ((WebRequestEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebRequestErrorEvent)
            {
                requestInformation = ((WebRequestErrorEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebErrorEvent)
            {
                requestInformation = ((WebErrorEvent)eventRaised).RequestInformation;
            }
            else if (eventRaised is WebAuditEvent)
            {
                requestInformation = ((WebAuditEvent)eventRaised).RequestInformation;
            }
            sqlCommand.Parameters[num++].Value = (requestInformation != null) ? requestInformation.RequestUrl : Convert.DBNull;
            if (eventRaised is WebBaseErrorEvent)
            {
                errorException = ((WebBaseErrorEvent)eventRaised).ErrorException;
            }
            sqlCommand.Parameters[num++].Value = (errorException != null) ? errorException.GetType().ToString() : Convert.DBNull;
            str = eventRaised.ToString();
            if ((this._maxEventDetailsLength != -1) && (str.Length > this._maxEventDetailsLength))
            {
                str = str.Substring(0, this._maxEventDetailsLength);
            }
            sqlCommand.Parameters[num++].Value = str;
        }
 private void FillParams(SqlCommand sqlCommand, WebBaseEvent eventRaised)
 {
     Exception errorException = null;
     WebRequestInformation requestInformation = null;
     string str = null;
     WebApplicationInformation applicationInformation = WebBaseEvent.ApplicationInformation;
     int num = 0;
     sqlCommand.Parameters[num++].Value = eventRaised.EventID.ToString("N", CultureInfo.InstalledUICulture);
     sqlCommand.Parameters[num++].Value = eventRaised.EventTimeUtc;
     sqlCommand.Parameters[num++].Value = eventRaised.EventTime;
     sqlCommand.Parameters[num++].Value = eventRaised.GetType().ToString();
     sqlCommand.Parameters[num++].Value = eventRaised.EventSequence;
     sqlCommand.Parameters[num++].Value = eventRaised.EventOccurrence;
     sqlCommand.Parameters[num++].Value = eventRaised.EventCode;
     sqlCommand.Parameters[num++].Value = eventRaised.EventDetailCode;
     sqlCommand.Parameters[num++].Value = eventRaised.Message;
     sqlCommand.Parameters[num++].Value = applicationInformation.ApplicationPath;
     sqlCommand.Parameters[num++].Value = applicationInformation.ApplicationVirtualPath;
     sqlCommand.Parameters[num++].Value = applicationInformation.MachineName;
     if (eventRaised is WebRequestEvent)
     {
         requestInformation = ((WebRequestEvent) eventRaised).RequestInformation;
     }
     else if (eventRaised is WebRequestErrorEvent)
     {
         requestInformation = ((WebRequestErrorEvent) eventRaised).RequestInformation;
     }
     else if (eventRaised is WebErrorEvent)
     {
         requestInformation = ((WebErrorEvent) eventRaised).RequestInformation;
     }
     else if (eventRaised is WebAuditEvent)
     {
         requestInformation = ((WebAuditEvent) eventRaised).RequestInformation;
     }
     sqlCommand.Parameters[num++].Value = (requestInformation != null) ? requestInformation.RequestUrl : Convert.DBNull;
     if (eventRaised is WebBaseErrorEvent)
     {
         errorException = ((WebBaseErrorEvent) eventRaised).ErrorException;
     }
     sqlCommand.Parameters[num++].Value = (errorException != null) ? errorException.GetType().ToString() : Convert.DBNull;
     str = eventRaised.ToString();
     if ((this._maxEventDetailsLength != -1) && (str.Length > this._maxEventDetailsLength))
     {
         str = str.Substring(0, this._maxEventDetailsLength);
     }
     sqlCommand.Parameters[num++].Value = str;
 }
        internal override void SendMessage(WebBaseEvent eventRaised)
        {
            WebBaseEventCollection events = new WebBaseEventCollection(eventRaised);

            SendMessageInternal(
                events,                                                    // events
                Interlocked.Increment(ref _nonBufferNotificationSequence), // notificationSequence
                0,                                                         // begin
                DateTime.MinValue,                                         // lastFlush
                0,                                                         // discardedSinceLastFlush
                0,                                                         // eventsInBuffer
                MessageSequenceBase,                                       // messageSequence
                1,                                                         // messagesInNotification
                1,                                                         // eventsInNotification
                0);                                                        // eventsLostDueToMessageLimit
        }
Exemplo n.º 44
0
        // Processes the incoming events.
        // This method performs custom processing and, if
        // buffering is enabled, it calls the base.ProcessEvent
        // to buffer the event information.
        public override void ProcessEvent(WebBaseEvent eventRaised)
        {
            if (UseBuffering)
                // Buffering enabled, call the base event to
                // buffer event information.
                base.ProcessEvent(eventRaised);
            else
            {
                // Buffering disabled, store event info immediately.
                customInfo.AppendLine("Message Start");
                customInfo.AppendLine(string.Format("{0}", eventRaised.Message));
                customInfo.AppendLine("Message Stop");

                // Store the information in the specified file.
                StoreToFile(customInfo, logFilePath, FileMode.Append);

            }
        }
        public override void ProcessEvent(WebBaseEvent eventRaised) 
        { 
            if (_buffer) {
                // register the event with the buffer instead of writing it out 
                Debug.Trace("BufferedWebEventProvider", "Saving event to buffer: event=" + eventRaised.GetType().Name);
                _webEventBuffer.AddEvent(eventRaised);
            }
            else {
                WebEventBufferFlushInfo flushInfo = new WebEventBufferFlushInfo(
                                new WebBaseEventCollection(eventRaised),
                                EventNotificationType.Unbuffered,
                                0,
                                DateTime.MinValue,
                                0,
                                0);

                ProcessEventFlush(flushInfo);
            }
        } 
Exemplo n.º 46
0
 public static void Raise (WebBaseEvent event_raised)
 {
         throw new NotImplementedException ();
 }
        public override void ProcessEventFlush(WebEventBufferFlushInfo flushInfo) {
            int     eventsInNotification = flushInfo.Events.Count;
            int     eventsRemaining = eventsInNotification;
            bool    split = false;
            int     messageSequence = MessageSequenceBase;
            int     messagesInNotification;
            int     eventsToBeDiscarded = 0;
            bool    fatalError = false;
            
            if (eventsInNotification == 0) {
                return;
            }

            WebBaseEventCollection eventsToSend;
            WebBaseEvent[]  eventsChunk = null;

            // We will split based on MaxEventsPerMessage
            if (eventsInNotification > MaxEventsPerMessage) {
                split = true;

                // I use the below clumsy calculation instead of (a+b-1)/b is to avoid
                // Int32 overflow.
                messagesInNotification = eventsInNotification/MaxEventsPerMessage;
                if (eventsInNotification > messagesInNotification*MaxEventsPerMessage) {
                    messagesInNotification++;
                }

                // We will exceed the limit.
                if (messagesInNotification > MaxMessagesPerNotification) {
                    eventsToBeDiscarded = eventsInNotification - MaxMessagesPerNotification * MaxEventsPerMessage;
                    messagesInNotification = MaxMessagesPerNotification;
                    eventsInNotification -= eventsToBeDiscarded;
                }
            }
            else {
                messagesInNotification = 1;
            }

            // In each email we only send a max of MaxEventsPerMessage events
            for(int eventsSent = 0; 
                eventsSent < eventsInNotification;
                messageSequence++) {
                if (split) {
                    int chunkSize = Math.Min(MaxEventsPerMessage, eventsInNotification - eventsSent);

                    if (eventsChunk == null || eventsChunk.Length != chunkSize) {
                        eventsChunk = new WebBaseEvent[chunkSize];
                    }
                    
                    for(int i = 0; i < chunkSize; i++) {
                        eventsChunk[i] = flushInfo.Events[i + eventsSent];
                    }

                    eventsToSend = new WebBaseEventCollection(eventsChunk);
                }
                else {
                    eventsToSend = flushInfo.Events;
                }

                Debug.Trace("MailWebEventProvider", "Calling SendMessageInternal; # of events: " + eventsToSend.Count);


                SendMessage(
                    eventsToSend,
                    flushInfo,
                    eventsInNotification,
                    eventsInNotification - (eventsSent + eventsToSend.Count),  // eventsRemaining
                    messagesInNotification,
                    eventsToBeDiscarded,
                    messageSequence,
                    eventsSent,
                    out fatalError);

                if (fatalError) {
                    Debug.Trace("MailWebEventProvider", "Stop sending because we hit a fatal error");
                    break;
                }

                eventsSent += eventsToSend.Count;
            }
        }
        /// <summary>
        /// Processes the event passed to the provider.
        /// </summary>
        /// <param name="raisedEvent"></param>
        public override void ProcessEvent(WebBaseEvent raisedEvent)
        {
            //make SURE we're really running in the web server so we don't mess up aspnet_compiler.
            if (m_NotInAspNet)
                return;

            try
            {
                //lets see if this is an event we're going to ignore to keep the log clean.
                if (raisedEvent.EventCode == WebEventCodes.AuditUrlAuthorizationSuccess)
                    return; //this is an ignorable audit success, who cares.
                if (raisedEvent.EventCode == WebEventCodes.AuditFileAuthorizationSuccess)
                    return; //this is an ignorable audit success, who cares.
                if (raisedEvent.EventCode == WebEventCodes.ApplicationHeartbeat)
                    return; //the user has other ways of knowing we're alive, we don't want to record this.
                if (raisedEvent.EventCode == WebEventCodes.ApplicationShutdown)
                {
                    //call end session and tell it our sucess information
                    Log.EndSession(SessionStatus.Normal, raisedEvent.Message);
                    return;
                }

                string categoryName = "System.Events." + GetEventCodeCategoryName(raisedEvent.EventCode);

                string caption = raisedEvent.Message;
                string description = null;
                
                Exception exception = null;
                LogMessageSeverity severity;

                Uri requestUri = null;
                WebProcessInformation processInformation = null;
                WebRequestInformation requestInformation = null;
                WebThreadInformation threadInformation = null;

                //process types we explicitly understand first

                if (raisedEvent is WebSuccessAuditEvent)
                {
                    //it's an otherwise unknown inheritor of the success event, treat it as such.
                    WebSuccessAuditEvent specificEvent = raisedEvent as WebSuccessAuditEvent;

                    severity = LogMessageSeverity.Verbose;
                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebViewStateFailureAuditEvent)
                {
                    //it's an otherwise unknown inheritor of the failure audit event, treat it as such.
                    WebViewStateFailureAuditEvent specificEvent = raisedEvent as WebViewStateFailureAuditEvent;

                    severity = LogMessageSeverity.Error;
                    exception = specificEvent.ViewStateException;
                    GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier.

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebFailureAuditEvent)
                {
                    //it's an otherwise unknown inheritor of the failure event, treat it as such.
                    WebFailureAuditEvent specificEvent = raisedEvent as WebFailureAuditEvent;

                    severity = LogMessageSeverity.Warning;

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebRequestEvent)
                {
                    //it's an otherwise unknown inheritor of the request event, treat it as such.
                    WebRequestEvent specificEvent = raisedEvent as WebRequestEvent;

                    severity = LogMessageSeverity.Information;

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                }
                else if (raisedEvent is WebRequestErrorEvent)
                {
                    //it's an otherwise unknown inheritor of the request error event, treat it as such.
                    WebRequestErrorEvent specificEvent = raisedEvent as WebRequestErrorEvent;

                    severity = LogMessageSeverity.Error;
                    exception = specificEvent.ErrorException;
                    GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier.

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                    threadInformation = specificEvent.ThreadInformation;
                }
                else if (raisedEvent is WebErrorEvent)
                {
                    //it's an otherwise unknown inheritor of the error event, treat it as such.
                    WebErrorEvent specificEvent = raisedEvent as WebErrorEvent;

                    severity = LogMessageSeverity.Error;
                    exception = specificEvent.ErrorException;
                    GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier.

                    processInformation = specificEvent.ProcessInformation;
                    requestInformation = specificEvent.RequestInformation;
                    threadInformation = specificEvent.ThreadInformation;
                }
                else if (raisedEvent is WebBaseErrorEvent)
                {
                    //it's an otherwise unknown inheritor of the base error event, treat it as such.
                    WebBaseErrorEvent specificEvent = raisedEvent as WebBaseErrorEvent;

                    exception = specificEvent.ErrorException;
                    severity = LogMessageSeverity.Error;

                    processInformation = specificEvent.ProcessInformation;
                }
                else if (raisedEvent is WebApplicationLifetimeEvent)
                {
                    WebApplicationLifetimeEvent specificEvent = raisedEvent as WebApplicationLifetimeEvent;

                    //we use different severities for two scenarios:  Compilation and startup/shutdown
                    if ((raisedEvent.EventCode == WebEventCodes.ApplicationCompilationStart)
                        || (raisedEvent.EventCode == WebEventCodes.ApplicationCompilationEnd))
                    {
                        severity = LogMessageSeverity.Verbose;
                    }
                    else
                    {
                        severity = LogMessageSeverity.Information;
                    }

                    processInformation = specificEvent.ProcessInformation;
                }
                else if (raisedEvent is WebManagementEvent)
                {
                    //it's an otherwise unknown inheritor of the management event, treat it as such.
                    WebManagementEvent specificEvent = raisedEvent as WebManagementEvent;

                    severity = LogMessageSeverity.Information;

                    processInformation = specificEvent.ProcessInformation;
                }
                else
                {
                    //overly simple initial implementation
                    severity = LogMessageSeverity.Information;
                }

                //see if we can populate more fields based on ASP-NET objects
                string userName = null;
                if (processInformation != null)
                {
                    userName = processInformation.AccountName;
                }

                if (threadInformation != null)
                {
                    //thread user name better than process user name
                    userName = threadInformation.ThreadAccountName;
                }

                string detailsXml = null;
                if (requestInformation != null)
                {
                    //if there is a current principal, that's our favorite answer.
                    IPrincipal currentPrincipal = requestInformation.Principal;
                    IIdentity currentIdentity = null;
                    if (currentPrincipal != null)
                    {
                        currentIdentity = currentPrincipal.Identity;
                    }

                    userName = currentIdentity != null ? currentIdentity.Name : requestInformation.ThreadAccountName;

                    detailsXml = GetRequestXml(requestInformation);

                    if (string.IsNullOrEmpty(requestInformation.RequestUrl) == false)
                    {
                        try
                        {
                            requestUri = new Uri(requestInformation.RequestUrl);
                        }
                        catch (Exception ex)
                        {
                            GC.KeepAlive(ex);
#if DEBUG
                            Log.RecordException(ex, "System", true);
#endif
                        }
                    }
                }

                //three ways we create our message source provider: Exception (best), Thread info (gotta parse, but accurate), and Request INfo (fake location)
                IMessageSourceProvider requestSource = null;
                if (exception != null)
                {
                    requestSource = new ExceptionSourceProvider(exception);
                }
                else if (requestInformation != null)
                {
                    requestSource = new WebRequestSourceProvider(requestInformation, requestUri);
                }
                else if (raisedEvent.EventSource != null)
                {
                    requestSource = new WebRequestSourceProvider(raisedEvent.EventSource);
                }

                //if we haven't figured out a class name by now, BS it using our event source.
                if ((requestSource as WebRequestSourceProvider != null) 
                    && (string.IsNullOrEmpty(requestSource.ClassName) && (raisedEvent.EventSource != null)))
                {
                    (requestSource as WebRequestSourceProvider).SetSource(raisedEvent.EventSource);
                }

                Log.Write(severity, LogSystem, requestSource, userName, exception, LogWriteMode.Queued, detailsXml, categoryName, caption, description);
            }
            catch (Exception ex)
            {
                GC.KeepAlive(ex);

#if DEBUG
                Log.RecordException(ex, "System", true);
#endif
            }
        }
 internal abstract void SendMessage(WebBaseEvent eventRaised);
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
     Debug.Trace("MailWebEventProvider", "ProcessEvent: type =" + eventRaised.GetType() + 
                     ", ID=" + eventRaised.EventID + ", buffer=" + UseBuffering);
     if (UseBuffering) {
         base.ProcessEvent(eventRaised);
     }
     else {
         SendMessage(eventRaised);
     }
 }
 internal override void RaiseTraceEvent(WebBaseEvent webEvent) {
     if (IntPtr.Zero != _ecb) {
         if (EtwTrace.IsTraceEnabled(webEvent.InferEtwTraceVerbosity(), EtwTraceFlags.Infrastructure)) {
             int fieldCount;
             string[] fieldNames;
             int[] fieldTypes;
             string[] fieldData;
             int webEventType;
             webEvent.DeconstructWebEvent(out webEventType, out fieldCount, out fieldNames, out fieldTypes, out fieldData);
         UnsafeNativeMethods.EcbEmitWebEventTrace(_ecb, webEventType, fieldCount, fieldNames, fieldTypes, fieldData);
         }
     }
 }
 public abstract void ProcessEvent(WebBaseEvent raisedEvent);
 internal override void RaiseTraceEvent(WebBaseEvent webEvent)
 {
     if ((this._traceEnabled && (this._context != IntPtr.Zero)) && EtwTrace.IsTraceEnabled(webEvent.InferEtwTraceVerbosity(), 1))
     {
         int num;
         string[] strArray;
         int[] numArray;
         string[] strArray2;
         int num2;
         webEvent.DeconstructWebEvent(out num2, out num, out strArray, out numArray, out strArray2);
         UnsafeIISMethods.MgdEmitWebEventTrace(this._context, num2, num, strArray, numArray, strArray2);
     }
 }
 internal void AddEvent(WebBaseEvent webEvent)
 {
     lock (this._buffer)
     {
         if (this._buffer.Count == this._maxBufferSize)
         {
             this._buffer.Dequeue();
             this._discardedSinceLastFlush++;
         }
         this._buffer.Enqueue(webEvent);
         if (this._buffer.Count >= this._urgentFlushThreshold)
         {
             this.Flush(this._maxFlushSize, FlushCallReason.UrgentFlushThresholdExceeded);
         }
         this._lastAdd = DateTime.UtcNow;
     }
 }
        internal void Flush(int max, FlushCallReason reason)
        {
            WebBaseEvent[] events = null;
            DateTime utcNow = DateTime.UtcNow;
            long waitTimeMs = 0L;
            DateTime maxValue = DateTime.MaxValue;
            int eventsDiscardedSinceLastNotification = -1;
            int eventsInBuffer = -1;
            int num4 = 0;
            EventNotificationType regular = EventNotificationType.Regular;
            bool flag = true;
            bool flag2 = false;
            bool flag3 = false;
            lock (this._buffer)
            {
                if (this._buffer.Count == 0)
                {
                    flag = false;
                }
                switch (reason)
                {
                    case FlushCallReason.UrgentFlushThresholdExceeded:
                        if (!this._urgentFlushScheduled)
                        {
                            break;
                        }
                        return;

                    case FlushCallReason.Timer:
                        if (this._regularFlushIntervalMs != Infinite)
                        {
                            flag2 = true;
                            waitTimeMs = this.GetNextRegularFlushDueTimeInMs();
                        }
                        goto Label_00D3;

                    default:
                        goto Label_00D3;
                }
                flag = false;
                flag2 = true;
                flag3 = true;
                if (this.AnticipateBurst(utcNow))
                {
                    waitTimeMs = this._burstWaitTimeMs;
                }
                else
                {
                    waitTimeMs = 0L;
                }
                TimeSpan span = (TimeSpan) (utcNow - this._lastScheduledFlushTime);
                long totalMilliseconds = (long) span.TotalMilliseconds;
                if ((totalMilliseconds + waitTimeMs) < this._urgentFlushIntervalMs)
                {
                    waitTimeMs = this._urgentFlushIntervalMs - totalMilliseconds;
                }
            Label_00D3:
                if (flag)
                {
                    if (this._threadsInFlush >= this._maxBufferThreads)
                    {
                        num4 = 0;
                    }
                    else
                    {
                        num4 = Math.Min(this._buffer.Count, max);
                    }
                }
                if (flag)
                {
                    if (num4 > 0)
                    {
                        events = new WebBaseEvent[num4];
                        for (int i = 0; i < num4; i++)
                        {
                            events[i] = (WebBaseEvent) this._buffer.Dequeue();
                        }
                        maxValue = this._lastFlushTime;
                        this._lastFlushTime = utcNow;
                        if (reason == FlushCallReason.Timer)
                        {
                            this._lastScheduledFlushTime = utcNow;
                        }
                        eventsDiscardedSinceLastNotification = this._discardedSinceLastFlush;
                        this._discardedSinceLastFlush = 0;
                        if (reason == FlushCallReason.StaticFlush)
                        {
                            regular = EventNotificationType.Flush;
                        }
                        else
                        {
                            regular = this._regularTimeoutUsed ? EventNotificationType.Regular : EventNotificationType.Urgent;
                        }
                    }
                    eventsInBuffer = this._buffer.Count;
                    if (eventsInBuffer >= this._urgentFlushThreshold)
                    {
                        flag2 = true;
                        flag3 = true;
                        waitTimeMs = this._urgentFlushIntervalMs;
                    }
                }
                this._urgentFlushScheduled = false;
                if (flag2)
                {
                    if (flag3)
                    {
                        long nextRegularFlushDueTimeInMs = this.GetNextRegularFlushDueTimeInMs();
                        if (nextRegularFlushDueTimeInMs < waitTimeMs)
                        {
                            waitTimeMs = nextRegularFlushDueTimeInMs;
                            this._regularTimeoutUsed = true;
                        }
                        else
                        {
                            this._regularTimeoutUsed = false;
                        }
                    }
                    else
                    {
                        this._regularTimeoutUsed = true;
                    }
                    this.SetTimer(waitTimeMs);
                    this._urgentFlushScheduled = flag3;
                }
                if ((reason == FlushCallReason.Timer) && !flag2)
                {
                    this._timer.Dispose();
                    this._timer = null;
                    this._urgentFlushScheduled = false;
                }
                if (events != null)
                {
                    Interlocked.Increment(ref this._threadsInFlush);
                }
            }
            if (events != null)
            {
                ApplicationImpersonationContext context = new ApplicationImpersonationContext();
                try
                {
                    WebEventBufferFlushInfo flushInfo = new WebEventBufferFlushInfo(new WebBaseEventCollection(events), regular, Interlocked.Increment(ref this._notificationSequence), maxValue, eventsDiscardedSinceLastNotification, eventsInBuffer);
                    this._flushCallback(flushInfo);
                }
                catch (Exception exception)
                {
                    try
                    {
                        this._provider.LogException(exception);
                    }
                    catch
                    {
                    }
                }
                catch
                {
                    try
                    {
                        this._provider.LogException(new Exception(System.Web.SR.GetString("Provider_Error")));
                    }
                    catch
                    {
                    }
                }
                finally
                {
                    if (context != null)
                    {
                        ((IDisposable) context).Dispose();
                    }
                }
                Interlocked.Decrement(ref this._threadsInFlush);
            }
        }
Exemplo n.º 56
0
 public override void ProcessEvent(WebBaseEvent raisedEvent)
 {
     throw new NotImplementedException();
 }
 public override void ProcessEvent(WebBaseEvent raisedEvent)
 {
     _simpleProvider.ProcessEvent(raisedEvent);
 }
 public override void ProcessEvent(WebBaseEvent eventRaised)
 {
 }
 internal virtual void RaiseTraceEvent(WebBaseEvent webEvent)
 {
 }