I use log4net for diagnostic logging in my applications, that is, if log4net doesn't work, the application runs fine anyway. I have a separate Audit Trail log that will block the application if the audit trail fails.
I want to include Audit Trail messages in my log4net logs, but I have a conundrum: I want the AuditTrail messages to be output with the highest priority (Critical like), but I don't want the audit trail messages to be represented as fatal errors.
They should be emitted with an INFO level, given they are not critical errors, but simply mandatory messages.
I was looking into the internals of log4net and I stumbled upon the protected Logger.Forcedlog method:
/// <summary>
/// Creates a new logging event and logs the event without further checks.
/// </summary>
/// <param name="logEvent">The event being logged.</param>
/// <remarks>
/// <para>
/// Delivers the logging event to the attached appenders.
/// </para>
/// </remarks>
protected virtual void ForcedLog(LoggingEvent logEvent)
{
logEvent.EnsureRepository((ILoggerRepository) this.Hierarchy);
this.CallAppenders(logEvent);
}
I can call this method via reflection and bypass any level check, but I'm feeling very guilty.
Are there any "cleaner" alternatives?