C # Экстремальное дублирование записей журнала в таблице базы данных - PullRequest
0 голосов
/ 18 мая 2018

Этот класс C # делает много дубликатов в моей таблице Oracle DB, как я могу оптимизировать исправление, чтобы не делать этого, но все равно делать журналы / отчеты об ошибках?Я включил код для методов, которые создают журналы.

Снимок экрана дубликатов в таблице БД:

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));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...