Esempio n. 1
0
        public void InsertAuditLog(AuditLog log)
        {
            _policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddHours(10.00) };

            if (log.TimeStamp == DateTime.MinValue)
            {
                log.TimeStamp = DateTime.UtcNow;
            }

            Cache.Set(log.TimeStamp.ToString(CultureInfo.InvariantCulture), log, _policy);
        }
Esempio n. 2
0
        private static AuditLog GetAuditLog(string action, IJobExecutionContext context)
        {
            var trigger = context.Trigger;
            var auditLog = new AuditLog
            {
                Action = action,
                TimeStamp = DateTime.UtcNow,
                FireInstanceId = context.FireInstanceId,
                FireTimeUtc = context.FireTimeUtc,
                ScheduledFireTimeUtc = context.ScheduledFireTimeUtc,
                JobName = context.JobDetail.Key.Name,
                JobGroup = context.JobDetail.Key.Group,
                TriggerName = trigger.Key.Name,
                TriggerGroup = trigger.Key.Group,
                JobRunTime = context.JobRunTime,
                JobType = context.JobDetail.JobType.Name,
                Params = JsonConvert.SerializeObject(context.MergedJobDataMap),
                RefireCount = context.RefireCount,
                Recovering = context.Recovering,
                Result = (context.Result != null) ? context.Result.ToString() : null
            };

            return auditLog;
        }
Esempio n. 3
0
        /// <summary>
        /// Insert AuditLog. 
        /// Each entry is read-only.
        /// </summary>
        /// <param name="log"></param>
        public void InsertAuditLog(AuditLog log)
        {
            const string sqlInsert = @"INSERT INTO RSCHED_AUDIT_HISTORY(time_stamp
                                                               ,action
                                                               ,fire_instance_id
                                                               ,job_name
                                                               ,job_group
                                                               ,job_type
                                                               ,trigger_name
                                                               ,trigger_group
                                                               ,fire_time_utc
                                                               ,scheduled_fire_time_utc
                                                               ,job_run_time
                                                               ,params
                                                               ,refire_count
                                                               ,recovering
                                                               ,result
                                                               ,execution_exception) 
                                                            VALUES (
                                                                :timeStamp, 
                                                                :action, 
                                                                :fireInstanceId, 
                                                                :jobName, 
                                                                :jobGroup, 
                                                                :jobType, 
                                                                :triggerName, 
                                                                :triggerGroup, 
                                                                :fireTimeUtc, 
                                                                :scheduledFireTimeUtc, 
                                                                :jobRunTime, 
                                                                :params, 
                                                                :refireCount, 
                                                                :recovering, 
                                                                :result, 
                                                                :executionException);";


            using (var con = new NpgsqlConnection(_connectionString))
            {
                try
                {
                    con.Open();
                    using (var command = new NpgsqlCommand(sqlInsert, con))
                    {
                        command.Parameters.Add(new NpgsqlParameter("timeStamp", NpgsqlDbType.Timestamp));
                        command.Parameters.Add(new NpgsqlParameter("action", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("fireInstanceId", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("jobName", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("jobGroup", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("jobType", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("triggerName", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("triggerGroup", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("fireTimeUtc", NpgsqlDbType.TimestampTZ));
                        command.Parameters.Add(new NpgsqlParameter("scheduledFireTimeUtc", NpgsqlDbType.TimestampTZ));
                        command.Parameters.Add(new NpgsqlParameter("jobRunTime", NpgsqlDbType.Bigint));
                        command.Parameters.Add(new NpgsqlParameter("params", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("refireCount", NpgsqlDbType.Integer));
                        command.Parameters.Add(new NpgsqlParameter("recovering", NpgsqlDbType.Boolean));
                        command.Parameters.Add(new NpgsqlParameter("result", NpgsqlDbType.Varchar));
                        command.Parameters.Add(new NpgsqlParameter("executionException", NpgsqlDbType.Varchar));

                        command.Parameters[0].Value = DateTime.UtcNow;
                        command.Parameters[1].Value = log.Action;
                        command.Parameters[2].Value = log.FireInstanceId;
                        command.Parameters[3].Value = log.JobName;
                        command.Parameters[4].Value = log.JobGroup;
                        command.Parameters[5].Value = log.JobType;
                        command.Parameters[6].Value = log.TriggerName;
                        command.Parameters[7].Value = log.TriggerGroup;
                        command.Parameters[8].Value = log.FireTimeUtc;
                        command.Parameters[9].Value = log.ScheduledFireTimeUtc;
                        command.Parameters[10].Value = log.JobRunTime.Ticks;
                        command.Parameters[11].Value = log.Params;
                        command.Parameters[12].Value = log.RefireCount;
                        command.Parameters[13].Value = log.Recovering;
                        command.Parameters[14].Value = log.Result ?? string.Empty;
                        command.Parameters[15].Value = log.ExecutionException ?? string.Empty;

                        command.ExecuteScalar();
                    }
                }
                catch (Exception ex)
                {
                    AuditLogLogger.Error("Error persisting AuditLog.", ex);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Insert AuditLog. 
        /// Each entry is read-only.
        /// </summary>
        /// <param name="log"></param>
        public void InsertAuditLog(AuditLog log)
        {
            const string sqlInsert = @"INSERT INTO RSCHED_AUDIT_HISTORY([TIME_STAMP]
                                                               ,[ACTION]
                                                               ,[FIRE_INSTANCE_ID]
                                                               ,[JOB_NAME]
                                                               ,[JOB_GROUP]
                                                               ,[JOB_TYPE]
                                                               ,[TRIGGER_NAME]
                                                               ,[TRIGGER_GROUP]
                                                               ,[FIRE_TIME_UTC]
                                                               ,[SCHEDULED_FIRE_TIME_UTC]
                                                               ,[JOB_RUN_TIME]
                                                               ,[PARAMS]
                                                               ,[REFIRE_COUNT]
                                                               ,[RECOVERING]
                                                               ,[RESULT]
                                                               ,[EXECUTION_EXCEPTION]) 
                                                            VALUES (
                                                                @timeStamp, 
                                                                @action, 
                                                                @fireInstanceId, 
                                                                @jobName, 
                                                                @jobGroup, 
                                                                @jobType, 
                                                                @triggerName, 
                                                                @triggerGroup, 
                                                                @fireTimeUtc, 
                                                                @scheduledFireTimeUtc, 
                                                                @jobRunTime, 
                                                                @params, 
                                                                @refireCount, 
                                                                @recovering, 
                                                                @result, 
                                                                @executionException);";

            using (var con = new SqlConnection(_connectionString))
            {
                try
                {
                    con.Open();
                    using (var command = new SqlCommand(sqlInsert, con))
                    {
                        command.Parameters.AddWithValue("@timeStamp", DateTime.UtcNow);
                        command.Parameters.AddWithValue("@action", log.Action);
                        command.Parameters.AddWithValue("@fireInstanceId", log.FireInstanceId);
                        command.Parameters.AddWithValue("@jobName", log.JobName);
                        command.Parameters.AddWithValue("@jobGroup", log.JobGroup);
                        command.Parameters.AddWithValue("@jobType", log.JobType);
                        command.Parameters.AddWithValue("@triggerName", log.TriggerName);
                        command.Parameters.AddWithValue("@triggerGroup", log.TriggerGroup);
                        command.Parameters.AddWithValue("@fireTimeUtc", log.FireTimeUtc);
                        command.Parameters.AddWithValue("@scheduledFireTimeUtc", log.ScheduledFireTimeUtc);
                        command.Parameters.AddWithValue("@jobRunTime", log.JobRunTime.Ticks);
                        command.Parameters.AddWithValue("@params", log.Params);
                        command.Parameters.AddWithValue("@refireCount", log.RefireCount);
                        command.Parameters.AddWithValue("@recovering", log.Recovering);
                        command.Parameters.AddWithValue("@result", log.Result ?? string.Empty);
                        command.Parameters.AddWithValue("@executionException", log.ExecutionException ?? string.Empty);

                        command.ExecuteScalar();
                    }
                }
                catch (Exception ex)
                {
                    AuditLogLogger.Error("Error persisting AuditLog.", ex);
                }
            }
        }
        private static AuditLog GetAuditLog(ITrigger trigger, string action, IJobExecutionContext context = null)
        {
            var auditLog = new AuditLog
            {
                Action = action,
                TimeStamp = DateTime.UtcNow,
                JobName = trigger.JobKey.Name,
                JobGroup = trigger.JobKey.Group,
                TriggerName = trigger.Key.Name,
                TriggerGroup = trigger.Key.Group,
            };

            if (context != null)
            {
                auditLog.FireInstanceId = context.FireInstanceId;
                auditLog.FireTimeUtc = context.FireTimeUtc;
                auditLog.FireTimeUtc = context.FireTimeUtc;
                auditLog.ScheduledFireTimeUtc = context.ScheduledFireTimeUtc;
                auditLog.JobRunTime = context.JobRunTime;
                auditLog.JobType = context.JobDetail.JobType.Name;
                auditLog.Params = JsonConvert.SerializeObject(context.MergedJobDataMap);
                auditLog.RefireCount = context.RefireCount;
                auditLog.Recovering = context.Recovering;
                auditLog.Result = (context.Result != null) ? context.Result.ToString() : null;
            }

            return auditLog;
        }