/// <summary> /// Writes the specified message with a retry. /// </summary> /// <param name="message">The message.</param> private void WriteWithRetry(SyslogMessage message) { int retryCount = 0; while (true) { bool retry = false; try { _messageWriter.Write(message); } catch (Exception ex) { retry = (_maxRetries > 0) && (++retryCount <= _maxRetries); if (retry) { Trace.TraceWarning("An error occurred writing syslog message MsgId:{0}. Retry count:{1}. Error:{2}.", message.MsgId, retryCount, ex); } else { Trace.TraceError("An error occurred writing syslog message MsgId:{0}. Error:{1}.", message.MsgId, ex); } } if (!retry) { break; } } }
/// <summary> /// Writes the specified audit log entry. /// </summary> /// <param name="entryData">The entry data.</param> /// <exception cref="System.ArgumentNullException">entryData</exception> public void Write(IAuditLogEntryData entryData) { if (entryData == null) { throw new ArgumentNullException(nameof(entryData)); } using (new SecurityBypassContext()) { var syslogMessage = new SyslogMessage { Facility = SyslogFacility.LogAudit, Severity = ConvertToSyslogSeverity(entryData.SeverityEnum), Timestamp = new DateTimeOffset(entryData.CreatedDate), HostName = _hostName, AppName = _applicationName, ProcId = _processName, MsgId = entryData.AuditLogEntryMetadata.MessageId }; syslogMessage.StructuredDataElements.Add(CreateBaseMsgData(entryData)); syslogMessage.StructuredDataElements.Add(CreateSpecificMsgData(entryData)); syslogMessage.StructuredDataElements.Add(CreateSystemInfoData()); syslogMessage.StructuredDataElements.Add(CreateOriginData(_ipHostEntry)); _syslogMessageWriter.Write(syslogMessage); } }
/// <summary> /// Writes the event log entry to syslog. /// </summary> /// <param name="logEntry">The log entry.</param> public void WriteEntry(EventLogEntry logEntry) { if (logEntry == null || !CanWriteEntry(logEntry.Level)) { return; } SyslogMessage sysLogMessage = ConvertToSyslogMessage(logEntry); _syslogWriter.Write(sysLogMessage); }