public void Log(string category, string caption, string userName, IMessageSourceProvider tracker)
        {
            var descriptionBuilder = new StringBuilder(1024);

            AddSessionIds(descriptionBuilder);

            descriptionBuilder.AppendFormat("Controller: {0}\r\n", _context.Controller());
            descriptionBuilder.AppendFormat("Action: {0}\r\n", _context.Action());
            if (_configuration.LogRequestParameters)
            {
                descriptionBuilder.AppendLine("Parameters:");
                foreach (var param in _context.GetParameters())
                {
                    object value = _context.GetParameter(param);
                    descriptionBuilder.AppendFormat("- {0}: {1}\r\n", param,
                        Extensions.ObjectToString(value, _configuration.LogRequestParameterDetails));
                }
            }

            descriptionBuilder.AppendFormat("\r\nURL: {0}\r\n", HttpContext.Current.Request.Url);

            var details = CreateDetails();

            Agent.Log.Write(_configuration.RequestMessageSeverity, LogSystem, tracker, userName, null,
                LogWriteMode.Queued, details, category, caption, descriptionBuilder.ToString());            
        }
Example #2
0
        public void Log(string category, string caption, string userName, IMessageSourceProvider tracker)
        {
            var descriptionBuilder = new StringBuilder(1024);

            AddSessionIds(descriptionBuilder);

            descriptionBuilder.AppendFormat("Controller: {0}\r\n", _context.Controller());
            descriptionBuilder.AppendFormat("Action: {0}\r\n", _context.Action());
            if (_configuration.LogRequestParameters)
            {
                descriptionBuilder.AppendLine("Parameters:");
                foreach (var param in _context.GetParameters())
                {
                    object value = _context.GetParameter(param);
                    descriptionBuilder.AppendFormat("- {0}: {1}\r\n", param,
                                                    Extensions.ObjectToString(value, _configuration.LogRequestParameterDetails));
                }
            }

            descriptionBuilder.AppendFormat("\r\nURL: {0}\r\n", HttpContext.Current.Request.Url);

            var details = CreateDetails();

            Agent.Log.Write(_configuration.RequestMessageSeverity, LogSystem, tracker, userName, null,
                            LogWriteMode.Queued, details, category, caption, descriptionBuilder.ToString());
        }
 public void SetSourceInfo(IMessageSourceProvider sourceProvider)
 {
     if (sourceProvider != null)
     {
         MethodName = sourceProvider.MethodName;
         ClassName  = sourceProvider.ClassName;
         FileName   = sourceProvider.FileName;
         LineNumber = sourceProvider.LineNumber;
     }
 }
 public void SetSourceInfo(IMessageSourceProvider sourceProvider)
 {
     if (sourceProvider != null)
     {
         // Note: Should we map null strings to empty strings here?
         MethodName = sourceProvider.MethodName;
         ClassName  = sourceProvider.ClassName;
         FileName   = sourceProvider.FileName;
         LineNumber = sourceProvider.LineNumber;
     }
 }
Example #5
0
        protected LogMessageBase(LogMessageSeverity severity, string logSystem, string categoryName, int skipFrames, bool localOrigin, bool attributeToException, Exception exception)
        {
            m_Severity     = severity;
            m_LogSystem    = logSystem;
            m_CategoryName = categoryName;

            if (attributeToException && (ReferenceEquals(exception, null) == false))
            {
                //try to use the exception as the source provider..
                var exceptionSourceProvider = new ExceptionSourceProvider(exception);
                if (string.IsNullOrEmpty(exceptionSourceProvider.ClassName) == false)
                {
                    //yep, we found something.
                    m_MessageSourceProvider = exceptionSourceProvider;
                }
            }

            m_MessageSourceProvider = m_MessageSourceProvider ?? new MessageSourceProvider(skipFrames + 1, localOrigin);
        }
Example #6
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
            }
        }
Example #7
0
 public void Write(LogMessageSeverity severity, string system, IMessageSourceProvider messageSource, IPrincipal?user, JavaScriptException?jsException,
                   LogWriteMode mode, string detailsBlock, string?category, string?caption, string?description, object[]?parameters)
 {
     Log.Write(severity, system, messageSource, user, jsException, mode, detailsBlock, category, caption, description, parameters);
 }
Example #8
0
 public MessageSourceProvider(IMessageSourceProvider callingProvider)
 {
     m_CallingProvider = callingProvider;
 }