private static void AddEvent(CUSTOMRP.Model.AUDITLOG auditlog) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("UserID = {0}\r\n", auditlog.UserID); sb.AppendFormat("Time = {0:yyyy/MM/dd HH:mm:ss}\r\n", auditlog.CreateDate); sb.AppendFormat("Type = {0}\r\n", Enum.GetName(typeof(CUSTOMRP.Model.AUDITLOG.Severity), auditlog.MessageType)); sb.AppendFormat("Module = {0}\r\n", auditlog.ModuleName); sb.AppendFormat("Message = {0}\r\n", auditlog.Message); sb.AppendFormat("Detail = {0}\r\n", auditlog.MessageDetail); using (System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog()) { appLog.Source = "Application"; appLog.WriteEntry(sb.ToString(), (auditlog.MessageType <= CUSTOMRP.Model.AUDITLOG.Severity.Warning) ? System.Diagnostics.EventLogEntryType.SuccessAudit : System.Diagnostics.EventLogEntryType.FailureAudit); } }
public static void Add(CUSTOMRP.Model.AUDITLOG auditlog) { const string strSQL = "INSERT INTO AUDITLOG (UserID, CreateDate, MessageType, ModuleName, Message, MessageDetail) VALUES (@UserID, @CreateDate, @MessageType, @ModuleName, @Message, @MessageDetail)"; try { DbHelperSQL.ExecuteSql(auditlog.UserID, strSQL, new SqlParameter("@UserID", auditlog.UserID), new SqlParameter("@CreateDate", auditlog.CreateDate), new SqlParameter("@MessageType", auditlog.MessageType), new SqlParameter("@ModuleName", auditlog.ModuleName), new SqlParameter("@Message", auditlog.Message), new SqlParameter("@MessageDetail", auditlog.MessageDetail) ); } catch { AddEvent(auditlog); } }