initial commit
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Microsoft.Extensions.Logging.Log4Net.AspNetCore.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Class with XmlDocument and XDocument extensions.
|
||||
/// </summary>
|
||||
internal static class DocumentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a XmlDocument object into xDocument.
|
||||
/// </summary>
|
||||
/// <param name="xmlDocument">The XML document.</param>
|
||||
/// <returns>The XmlDocument converted to XDocument</returns>
|
||||
public static XDocument ToXDocument(this XmlDocument xmlDocument)
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
xmlDocument.Save(memoryStream);
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
return XDocument.Load(memoryStream);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a XDocument object into XmlDocument
|
||||
/// </summary>
|
||||
/// <param name="xDocument">The x document.</param>
|
||||
/// <returns>The XDocument converted to XmlDocument</returns>
|
||||
public static XmlDocument ToXmlDocument(this XDocument xDocument)
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
xDocument.Save(memoryStream);
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
var xmlDoc = new XmlDocument();
|
||||
xmlDoc.Load(memoryStream);
|
||||
return xmlDoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.Extensions.Logging.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Log4Net provider extensions.
|
||||
/// </summary>
|
||||
public static class Log4NetProviderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a logger with the name of the given <see cref="TName"/> type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TName">The type of the class to be used as name of the logger.</typeparam>
|
||||
/// <param name="self">An ILoggerProvider instance.</param>
|
||||
/// <returns>An instance of the <see cref="ILogger"/>.</returns>
|
||||
public static ILogger CreateLogger<TName>(this ILoggerProvider self) where TName : class
|
||||
{
|
||||
if (self == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(self));
|
||||
}
|
||||
|
||||
if (!self.GetType().IsAssignableFrom(typeof(Log4NetProvider)))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(self), "The ILoggerProvider should be of type Log4NetProvider.");
|
||||
}
|
||||
|
||||
return self.CreateLogger(typeof(TName).FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using log4net;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Extensions.Logging.Log4Net.AspNetCore.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ILogExtensions"/> class.
|
||||
/// </summary>
|
||||
public static class LogExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Criticals the specified message.
|
||||
/// </summary>
|
||||
/// <param name="log">The log.</param>
|
||||
/// <param name="message">The message.</param>
|
||||
/// <param name="exception">The exception.</param>
|
||||
public static void Critical(this ILog log, object message, Exception exception)
|
||||
=> log.Logger.Log(null, log4net.Core.Level.Critical, message, exception);
|
||||
|
||||
/// <summary>
|
||||
/// Traces the specified message.
|
||||
/// </summary>
|
||||
/// <param name="log">The log.</param>
|
||||
/// <param name="message">The message.</param>
|
||||
/// <param name="exception">The exception.</param>
|
||||
public static void Trace(this ILog log, object message, Exception exception)
|
||||
=> log.Logger.Log(null, log4net.Core.Level.Trace, message, exception);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user