コード例 #1
0
        /// <summary>Saves the exception to database.</summary>
        /// <param name="transaction">The transaction.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="parentEventId">The parent event id.</param>
        /// <param name="parentExceptionId">The parent exception id.</param>
        /// <returns>
        /// The database's primary key of the saved exception.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown when either <paramref name="exception"/> or
        /// <paramref name="transaction"/> are null (Nothing in VB) references.</exception>
        protected override int SaveExceptionToDatabase(SqlTransaction transaction, Exception exception,
                                                       int parentEventId, int?parentExceptionId)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }

            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            using (var command = new SqlCommand(AddExceptionProcedure, transaction.Connection, transaction))
            {
                command.CommandType = CommandType.StoredProcedure;

                SqlLoggingHelper.AddParameter(command, "EventId", SqlDbType.Int, parentEventId);
                SqlLoggingHelper.AddParameter(command, "ParentExceptionId", SqlDbType.Int, parentExceptionId);
                SqlLoggingHelper.AddParameter(command, "ExceptionType", SqlDbType.NVarChar, exception.GetType().Name);
                SqlLoggingHelper.AddParameter(command, "Message", SqlDbType.NText, exception.Message);
                SqlLoggingHelper.AddParameter(command, "StackTrace", SqlDbType.NText, exception.StackTrace);

                object exceptionId = command.ExecuteScalar();

                if (!(exceptionId is int))
                {
                    throw new InvalidOperationException(SR.StoredProcedureReturnedInvalidValue(
                                                            AddExceptionProcedure, exceptionId, typeof(int)));
                }

                return((int)exceptionId);
            }
        }
コード例 #2
0
        private static bool GetLogQueryStringFromConfig(string name, NameValueCollection config)
        {
            const bool   DefaultValueWhenMissing = true;
            const string LogQueryStringAttribute = "logQueryString";

            bool logQueryString =
                SqlLoggingHelper.ParseBoolConfigValue(name, LogQueryStringAttribute,
                                                      config[LogQueryStringAttribute], DefaultValueWhenMissing);

            // Remove this attribute from the configuration. This way the provider can spot unrecognized
            // attributes after the initialization process.
            config.Remove(LogQueryStringAttribute);

            return(logQueryString);
        }
コード例 #3
0
        private static bool GetLogFormDataFromConfig(string name, NameValueCollection config)
        {
            const string LogFormDataAttribute = "logFormData";

            const bool DefaultValueWhenMissing = false;

            bool logFormData =
                SqlLoggingHelper.ParseBoolConfigValue(name, LogFormDataAttribute, config[LogFormDataAttribute],
                                                      DefaultValueWhenMissing);

            // Remove this attribute from the config. This way the provider can spot unrecognized attributes
            // after the initialization process.
            config.Remove(LogFormDataAttribute);

            return(logFormData);
        }
コード例 #4
0
        /// <summary>Initializes the database schema.</summary>
        protected override void InitializeDatabaseSchema()
        {
            try
            {
                SqlLoggingHelper.ThrowWhenSchemaAlreadyHasBeenInitialized(this);

                string createScript = SR.AspNetSqlLoggingProviderSchemaScripts();

                string[] createScripts = createScript.Split(new string[] { "GO" }, StringSplitOptions.None);

                SqlLoggingHelper.CreateTablesAndStoredProcedures(this, createScripts);
            }
            catch (SqlException ex)
            {
                throw new ProviderException(SR.InitializationOfDatabaseSchemaFailed(this.Name, ex.Message), ex);
            }
        }
コード例 #5
0
        /// <summary>Saves the event to database.</summary>
        /// <param name="transaction">The transaction.</param>
        /// <param name="severity">The event severity.</param>
        /// <param name="message">The message.</param>
        /// <param name="source">The source.</param>
        /// <returns>The database's primary key of the saved event.</returns>
        protected override int SaveEventToDatabase(SqlTransaction transaction, LoggingEventType severity,
                                                   string message, string source)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            var requestLogData =
                new RequestLogData(HttpContext.Current, this.logQueryString, this.logFormData);

            using (var command = new SqlCommand(AddEventProcedure, transaction.Connection, transaction))
            {
                command.CommandType = CommandType.StoredProcedure;

                SqlLoggingHelper.AddParameter(command, "EventTypeId", SqlDbType.Int, (int)severity);
                SqlLoggingHelper.AddParameter(command, "Message", SqlDbType.NText, message);
                SqlLoggingHelper.AddParameter(command, "Source", SqlDbType.NText, source);

                SqlLoggingHelper.AddParameter(command, "MachineName", SqlDbType.NVarChar, Environment.MachineName);
                SqlLoggingHelper.AddParameter(command, "ApplicationName", SqlDbType.NVarChar, this.ApplicationName);
                SqlLoggingHelper.AddParameter(command, "UserName", SqlDbType.NVarChar, this.GetCurrentUserName());
                SqlLoggingHelper.AddParameter(command, "IpAddress", SqlDbType.NVarChar, requestLogData.IpAddress);
                SqlLoggingHelper.AddParameter(command, "QueryString", SqlDbType.NText, requestLogData.QueryString);
                SqlLoggingHelper.AddParameter(command, "FormData", SqlDbType.NText, requestLogData.Form);

                object eventId = command.ExecuteScalar();

                if (!(eventId is int))
                {
                    throw new InvalidOperationException(SR.StoredProcedureReturnedInvalidValue(
                                                            AddEventProcedure, eventId, typeof(int)));
                }

                return((int)eventId);
            }
        }