internal LogWriter(Func <DateTime> timeProvider, ILogFileHelper logFileHelper) { _timeProvider = timeProvider ?? throw new ArgumentNullException(nameof(timeProvider)); _logFileHelper = logFileHelper ?? throw new ArgumentNullException(nameof(logFileHelper)); }
private void CreateNewWriter() { if (writer != null) { if (xmlBlobWriter != null) { xmlBlobWriter.Flush(); } writer.Flush(); writer.Close(); //writer = null; } string targetFileName = fileStaticName + DateTime.UtcNow.ToString(fileDatetimePattern); string pathCandidate = null; int maxIter = 10; for (int i = 1; i < maxIter; i++) { if (!File.Exists(logRootLocation + targetFileName + "_" + i + ".xml")) { pathCandidate = Path.Combine(logRootLocation, targetFileName + "_" + i + ".xml"); break; } } if (pathCandidate == null) { // fallback name, uses guid pathCandidate = Path.Combine(logRootLocation, fileStaticName + Guid.NewGuid() + ".xml"); } logFilePath = pathCandidate; if (textWriterProvider == null) { textWriterProvider = new FileTextWriterProvider( true, GetEncodingWithFallback(new UTF8Encoding(false)), 0x1000); } writer = textWriterProvider.CreateWriter(logFilePath); if (logFileHelper == null) { logFileHelper = new LogFileHelper(); } logFileHelper.MaxFileSizeBytes = maxFileSizeBytes; logFileHelper.FilePath = logFilePath; }