Example #1
0
        /// <summary>
        /// Log an activity that occurred at the specified date and time to the activity log 
        /// </summary>
        /// <param name="activityDate">Date the activity took place</param>
        /// <param name="tableName">Name of the table associated with the activity (if any)</param>
        /// <param name="keyId">Primary key of the record associated with the activity (if any)</param>
        /// <param name="user">User that performed the activity</param>
        /// <param name="activity">Description of the activity that took place</param>        
        public static void WriteUserActivity(DateTime activityDate, string tableName, int keyId, string user, string activity)
        {
            ActivityMessageAgent agent = null;

            try
            {
                var msg = new ActivityLogMessage
                              {
                                  Timestamp = activityDate,
                                  TableName = tableName,
                                  TableKeyId = keyId,
                                  Username = user,
                                  Activity = activity
                              };

                agent = new ActivityMessageAgent();
                agent.DispatchActivityLogMessage(msg);
            }
            catch (Exception ex)
            {
                LogException(user, ex);
                throw;
            }
            finally
            {
                if (agent != null)
                    agent.Close();
            }
        }
Example #2
0
        /// <summary>
        /// Log an activity that occurred at the specified date and time to the activity log.  
        /// Using the current IIdentity.Name as user.
        /// </summary>
        /// <param name="activityDate">Date the activity took place</param>
        /// <param name="tableName">Name of the table associated with the activity (if any)</param>
        /// <param name="keyId">Primary key of the record associated with the activity (if any)</param>        
        /// <param name="activity">Description of the activity that took place</param>        
        public static void WriteActivity(DateTime activityDate, string tableName, int keyId, string activity)
        {
            ActivityMessageAgent agent = null;

            var userName = System.Threading.Thread.CurrentPrincipal != null
                               ? System.Threading.Thread.CurrentPrincipal.Identity.Name
                               : Constants.SYSTEM_USER_NAME;

            try
            {
                var msg = new ActivityLogMessage
                {
                    Timestamp = activityDate,
                    TableName = tableName,
                    TableKeyId = keyId,
                    Username = userName,
                    Activity = activity
                };

                agent = new ActivityMessageAgent();
                agent.DispatchActivityLogMessage(msg);
            }
            catch (Exception ex)
            {
                LogException(Constants.SYSTEM_USER_NAME, ex);
                throw;
            }
            finally
            {
                if (agent != null)
                    agent.Close();
            }
        }