public override void Write(LogEntry entry) { Init(); if (Interval != null && Interval.Update()) { _logFile.Dispose(); _logFile = GetNextLogFile(); DeleteOldLogFiles(); } if (_logFile == null) { var file = IsPathDirectory(Path) ? new DirectoryInfo(Path).File("log.txt") : new FileInfo(Path); _logFile = CreateLogFile(file); } _logFile.FileInfo.Directory?.Create(); var fmt = EntryFormatter ?? entry.Logger.LogManager.GetFormatter<string>(); var msg = fmt.Convert(entry); _logFile.Append(msg); }
private void Init() { if (_initialized || Interval == null) return; Interval.Update(); _logFile = GetNextLogFile(); DeleteOldLogFiles(); _initialized = true; }
private void SendBuffer(LogManager logMgr) { // start logging to a new file LogFile oldFile; using(_tempFileLock.UseWriteLock()) { oldFile = _tempFile; _tempFile = GetTempFile(); } using (oldFile) { // email file if (oldFile.FileInfo.Exists && oldFile.FileInfo.Length > 0) { var subj = Subject ?? $"{AppDomain.CurrentDomain.FriendlyName} Log Entries"; var body = oldFile.ReadAllText(); Send(subj, body, logMgr); } // prepare for next period if (Interval == null) return; Interval.Update(); Interval.StartTimer(); } }
public EmailTarget() { _tempFile = GetTempFile(); }
private void SendBuffer() { // start logging to a new file LogFile oldFile; using (var lockmgr = new ReaderWriterLockMgr(_tempFileLock)) { lockmgr.EnterWriteLock(); oldFile = _tempFile; _tempFile = GetTempFile(); } using (oldFile) { // email file if (oldFile.FileInfo.Exists && oldFile.FileInfo.Length > 0) { var subj = Subject ?? string.Format("{0} Log Entries", AppDomain.CurrentDomain.FriendlyName); var body = oldFile.ReadAllText(); Send(subj, body); } // prepare for next period if (Interval == null) return; Interval.Update(); Interval.StartTimer(); } }