C#数据库表中的日志条目的极端重复

时间:2018-05-18 08:06:06

标签: c# database visual-studio-2010 database-design duplicates

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

数据库表中重复项的屏幕截图:

Duplicates in Database table

CreateLogEntryForAgent()

  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);
    }

CreateErrorLogEntry()

 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);
    }

CreateReportLogEntry

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));

0 个答案:

没有答案