/// <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);
            }
        }
示例#2
0
        /// <summary>
        /// Catches the Mediator message and invokes the <see cref="RequestLogData"/> event.
        /// </summary>
        /// <param name="value"></param>
        private void OnRequestLogData(object value)
        {
            List <object> list = (List <object>)value;

            RequestLogData?.Invoke(this, new ListArguments(list));
        }