这个C#类在我的Oracle数据库表中做了很多重复,我如何优化修复它不这样做,但仍然会生成日志/错误报告?我已经包含了创建日志的方法的代码。
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));