示例#1
0
 private void InitThreadInformation()
 {
     if (this._threadInfo == null)
     {
         this._threadInfo = new WebThreadInformation(base.ErrorException);
     }
 }
示例#2
0
        /// <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

                WebSuccessAuditEvent          webSuccessAuditEvent;
                WebViewStateFailureAuditEvent webViewStateFailureAuditEvent;
                WebFailureAuditEvent          webFailureAuditEvent;
                WebRequestEvent             webRequestEvent;
                WebRequestErrorEvent        webRequestErrorEvent;
                WebErrorEvent               webErrorEvent;
                WebBaseErrorEvent           webBaseErrorEvent;
                WebApplicationLifetimeEvent webApplicationLifetimeEvent;
                WebManagementEvent          webManagementEvent;

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

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

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

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

                    severity = LogMessageSeverity.Warning;

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

                    severity = LogMessageSeverity.Information;

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

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

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

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

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

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

                    processInformation = webBaseErrorEvent.ProcessInformation;
                }
                else if ((webApplicationLifetimeEvent = raisedEvent as WebApplicationLifetimeEvent) != null)
                {
                    //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 = webApplicationLifetimeEvent.ProcessInformation;
                }
                else if ((webManagementEvent = raisedEvent as WebManagementEvent) != null)
                {
                    //it's an otherwise unknown inheritor of the management event, treat it as such.

                    severity = LogMessageSeverity.Information;

                    processInformation = webManagementEvent.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
            }
        }
示例#3
0
 private void AddWebThreadInformationDataFields(LogRecord logrec, WebThreadInformation threadinfo)
 {
     logrec.ThreadId = threadinfo.ThreadID;
     logrec.Identity = threadinfo.ThreadAccountName;
 }