Inheritance: IDisposable
Example #1
0
        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);
        }
Example #2
0
        private void Init()
        {
            if (_initialized || Interval == null)
                return;

            Interval.Update();

            _logFile = GetNextLogFile();
            DeleteOldLogFiles();

            _initialized = true;
        }
Example #3
0
        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();
            }
        }
Example #4
0
 public EmailTarget()
 {
     _tempFile = GetTempFile();
 }
Example #5
0
        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();
            }
        }