C#数据库表中日志项的极端重复
这个C#类在我的Oracle DB表中产生了很多重复项,我如何优化并修复它,使其不产生重复项,但仍然生成日志/错误报告?我已经包含了创建日志的方法的代码 DB表中重复项的屏幕截图: CreateLogEntryForAgent() CreateErrorLogEntry() CreateReportLogEntry 方法调用的一个示例C#数据库表中日志项的极端重复,c#,database,visual-studio-2010,database-design,duplicates,C#,Database,Visual Studio 2010,Database Design,Duplicates,这个C#类在我的Oracle DB表中产生了很多重复项,我如何优化并修复它,使其不产生重复项,但仍然生成日志/错误报告?我已经包含了创建日志的方法的代码 DB表中重复项的屏幕截图: CreateLogEntryForAgent() CreateErrorLogEntry() CreateReportLogEntry 方法调用的一个示例 如果它们是完全重复的,那么您有两个明显的选择,可能还有一些不太明显的选择,1是当您分配日志时,您已经多次这样做,或者根据需要添加和删除日志,因此对于单个事件,它
如果它们是完全重复的,那么您有两个明显的选择,可能还有一些不太明显的选择,1是当您分配日志时,您已经多次这样做,或者根据需要添加和删除日志,因此对于单个事件,它会被多次调用。或者您保存上次记录的错误的副本,如果重复,可能会设置计数器。。然后,当它不再是原来的时候,为Clarity删除一条“上一条消息重复x次”的消息,我会认为您的日志代码不是问题所在。如果您正在复制日志记录条目,那么它向我建议调用日志记录程序的代码存在问题?每次我使用同步程序同步员工邮件时,都会调用该方法,我为此添加了代码
public static ApplicationLogEntry CreateLogEntryForAgent(string logText, LogTypes type) {
int agentId = 0;
int applicationVersionId = 0;
if(Environment.CurrentAgent.Value != null)
agentId = Environment.CurrentAgent.Value.Id;
if(Environment.CurrentApplication.Value != null &&
Environment.CurrentApplication.Value.GetCurrentVersion() != null)
applicationVersionId = Environment.CurrentApplication.Value.GetCurrentVersion().Id;
return new ApplicationLogEntry(DateTime.Now,
agentId,
SystemVars.GetComputerName(),
applicationVersionId,
logText,
type);
}
public static ApplicationLogEntry CreateErrorLogEntry(Exception exception, string applicationState) {
if(exception == null)
throw new ArgumentNullException("exception");
int agentId = 0;
int applicationVersionId = 0;
if(Environment.CurrentAgent.Value != null)
agentId = Environment.CurrentAgent.Value.Id;
if(Environment.CurrentApplication.Value != null &&
Environment.CurrentApplication.Value.GetCurrentVersion() != null)
applicationVersionId = Environment.CurrentApplication.Value.GetCurrentVersion().Id;
return new ApplicationLogEntry(DateTime.Now,
agentId,
SystemVars.GetComputerName(),
applicationVersionId,
ErrorLogging.CreateExceptionDescription(exception, SystemVars.GetAssemblyFullName(), applicationState, true),
LogTypes.Error);
}
public static ApplicationLogEntry CreateReportLogEntry(XmlDocument report) {
if(report == null)
throw new ArgumentNullException("report");
int agentId = 0;
int applicationVersionId = 0;
if(Environment.CurrentAgent.Value != null)
agentId = Environment.CurrentAgent.Value.Id;
if(Environment.CurrentApplication.Value != null &&
Environment.CurrentApplication.Value.GetCurrentVersion() != null)
applicationVersionId = Environment.CurrentApplication.Value.GetCurrentVersion().Id;
return new ApplicationLogEntry(DateTime.Now,
agentId,
SystemVars.GetComputerName(),
applicationVersionId,
report.OuterXml,
LogTypes.Report);
}
if(SystemVars.IsProductionEnvironment())
ApplicationLog.LogEvent(ApplicationLogEntry.CreateLogEntryForAgent("Application Closed", LogTypes.Notification));