initial commit
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
using log4net.Core;
|
||||
|
||||
namespace Microsoft.Extensions.Logging.Log4Net.AspNetCore.Entities;
|
||||
|
||||
// ref: http://svn.apache.org/viewvc/logging/log4net/trunk/examples/net/2.0/Extensibility/EventIDLogApp/cs/src/
|
||||
public class EventIDLogImpl : LogImpl, IEventIDLog
|
||||
{
|
||||
public EventIDLogImpl(log4net.Core.ILogger logger) : base(logger) { /* skip */ }
|
||||
|
||||
#region Implementation of IEventIDLog
|
||||
|
||||
public void Log(EventId eventId, LoggingEvent loggingEvent)
|
||||
{
|
||||
// is the EventId empty?
|
||||
if (!(eventId.Id == 0 && string.IsNullOrWhiteSpace(eventId.Name)))
|
||||
loggingEvent.Properties[nameof(EventId)] = eventId;
|
||||
|
||||
Logger.Log(loggingEvent);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using log4net;
|
||||
using log4net.Core;
|
||||
|
||||
namespace Microsoft.Extensions.Logging.Log4Net.AspNetCore.Entities;
|
||||
|
||||
public interface IEventIDLog : ILog
|
||||
{
|
||||
void Log(EventId eventId, LoggingEvent loggingEvent);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Extensions.Logging.Log4Net.AspNetCore.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a candidate for a log message that should be printed. This candidate will either be accepted or denied by the logger that is trying to print it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This is a readonly struct to reduce memory pressure, but because it is quite large (definitly larger than the recommended 16 bytes)
|
||||
/// it needs to be passed as a reference (with the in keyword) to make a difference.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// See <see href="https://devblogs.microsoft.com/premier-developer/the-in-modifier-and-the-readonly-structs-in-c/"/> for more information.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <typeparam name="TState">Type of the state that is used to format the error message.</typeparam>
|
||||
public readonly struct MessageCandidate<TState>
|
||||
{
|
||||
public MessageCandidate(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
{
|
||||
State = state;
|
||||
LogLevel = logLevel;
|
||||
EventId = eventId;
|
||||
Exception = exception;
|
||||
Formatter = formatter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log level the message should be printed with.
|
||||
/// </summary>
|
||||
public LogLevel LogLevel { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The event id of the message.
|
||||
/// </summary>
|
||||
public EventId EventId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The message state. Can be provided to the formatter to generate the string representation of the error message.
|
||||
/// </summary>
|
||||
public TState State { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Exception that should be printed with the message. Null if the log message has no corrosponding exception.
|
||||
/// </summary>
|
||||
public Exception Exception { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The message formatter. Can be called with the state and exception to generate the string representation of the error message.
|
||||
/// </summary>
|
||||
public Func<TState, Exception, string> Formatter { get; }
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.Extensions.Logging.Log4Net.AspNetCore.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to store information of a log4net xml config file node.
|
||||
/// </summary>
|
||||
public class NodeInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the x path to find the node to override.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The x path.
|
||||
/// </value>
|
||||
public string XPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the content of the node.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The content of the node.
|
||||
/// </value>
|
||||
public string NodeContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the attributes.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The attributes.
|
||||
/// </value>
|
||||
public Dictionary<string, string> Attributes { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user