Я использую блочную версию приложения Enterprise Library версии 6.0 в приложении. Сегодня приложение рухнуло в полночь, как записано в журнале событий.
Метка времени: 2019-03-27 00: 00: 00
Информация об исключении: System.NullReferenceException
в Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener + StreamWriterRollingHelper.PerformRoll (System.DateTime)
в Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener + StreamWriterRollingHelper.RollIfNeeded ()
в System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
в System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
в System.Threading.TimerQueueTimer.CallCallback ()
Настройка RollingFlatFileTraceListener из app.config
<add name="Flat File Destination"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
fileName="trace.log"
footer=""
formatter="Text Formatter"
header=""
rollFileExistsBehavior="Increment"
rollInterval="Midnight"
rollSizeKB="50000"
timeStampPattern="yyyy-MM-dd"
maxArchivedFiles="10"
traceOutputOptions="None"
filter="All" />
В файле трассировки есть записи в миллисекундах до и после полуночи. Таким образом, должен быть Доступ к файлу трассировки, пока он катится.
Я написал небольшую тестовую Программу, чтобы подчеркнуть регистратор приложений с теми же настройками, что и в моем аварийном приложении. Во время работы приложения я часто менял время на несколько секунд до полуночи, пытаясь воспроизвести исключение, но это не помогло.
Я открыл сборки приложения журналирования в версиях 5.0 и 6.0.
В версии 6.0 RollingFlatFileTraceListener имеет следующий конструктор:
public RollingFlatFileTraceListener(string fileName, string header = "----------------------------------------", string footer = "----------------------------------------", ILogFormatter formatter = null, int rollSizeKB = 0, string timeStampPattern = "yyyy-MM-dd", RollFileExistsBehavior rollFileExistsBehavior = 0, RollInterval rollInterval = 0, int maxArchivedFiles = 0) : base(fileName, header, footer, formatter)
{
Guard.ArgumentNotNullOrEmpty(fileName, "fileName");
this.rollSizeInBytes = rollSizeKB * 1024;
this.timeStampPattern = timeStampPattern;
this.rollFileExistsBehavior = rollFileExistsBehavior;
this.rollInterval = rollInterval;
this.maxArchivedFiles = maxArchivedFiles;
this.rollingHelper = new RollingFlatFileTraceListener.StreamWriterRollingHelper(this);
if (rollInterval == RollInterval.Midnight)
{
DateTime currentDateTime = this.rollingHelper.DateTimeProvider.CurrentDateTime;
DateTime date = currentDateTime.AddDays(1).Date;
this.timer = new Timer((object o) => this.rollingHelper.RollIfNecessary(), null, date.Subtract(currentDateTime), TimeSpan.FromDays(1));
}
}
Таким образом, с установкой интервала прокрутки на Midnight
запускается отдельный таймер, чтобы выполнить прокрутку файла трассировки, если это необходимо. Это было не так в V5.0.
Метод RollIfNecessary
также вызывается методом TraceData
. Я предполагаю, что при выполнении метода RollIfNecessary
возникает проблема с многопоточностью. Я не нашел блокировки в этом методе.
Может ли кто-нибудь подтвердить мое подозрение или возникли похожие проблемы?