/// <summary> /// Appends a <see cref="SysLogEntry" /> to the event log. /// </summary> /// <param name="entry">The log entry.</param> protected override void Append(SysLogEntry entry) { bool createNew; lock (syncLock) { try { using (var output = File.AppendText(currentFile)) { output.WriteLine(entry.ToString(SysLogEntryFormat.ShowAll)); createNew = output.BaseStream.Length >= maxSize; } if (createNew) { CreateNewFile(); } } catch { // Absorb any exceptions to avoid impacting the application due to logging issues. } } }
/// <summary> /// Appends the log entry passed to the in-memory list if in-memory /// logging is enabled, otherwise writes the entry to the output. /// </summary> /// <param name="entry">The log entry.</param> protected override void Append(SysLogEntry entry) { if (!inMemory) { if (fileName == null) { Debug.Write(entry.ToString()); } else { lock (syncLock) { FileStream output; byte[] buf; output = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.None); buf = Encoding.UTF8.GetBytes(entry.ToString(format)); output.Write(buf, 0, buf.Length); output.Close(); } } return; } lock (syncLock) { if (head == null) { head = tail = entry; } else { tail.Next = entry; } } }
/// <summary> /// Appends the log entry passed to the output log. /// </summary> /// <param name="entry">The log entry.</param> protected override void Append(SysLogEntry entry) { EventLogEntryType winEventType; if (appEventLog == null) { return; } switch (entry.Type) { case SysLogEntryType.Information: winEventType = EventLogEntryType.Information; break; case SysLogEntryType.Warning: winEventType = EventLogEntryType.Warning; break; case SysLogEntryType.Error: winEventType = EventLogEntryType.Error; break; case SysLogEntryType.SecuritySuccess: winEventType = EventLogEntryType.SuccessAudit; break; case SysLogEntryType.SecurityFailure: winEventType = EventLogEntryType.FailureAudit; break; case SysLogEntryType.Exception: winEventType = EventLogEntryType.Error; break; case SysLogEntryType.Trace: winEventType = EventLogEntryType.Information; break; default: winEventType = EventLogEntryType.Information; break; } try { appEventLog.WriteEntry(entry.ToString(SysLogEntryFormat.ShowExtended), winEventType); } catch { // The event log can throw an exception when it's full. Ignore these. } }