Skip to content

Commit

Permalink
Merge pull request #15 from shoftee/feature/add-new-style-exceptions
Browse files Browse the repository at this point in the history
Add new-style exceptions
  • Loading branch information
bugthesystem committed Oct 12, 2017
2 parents 887bc98 + 07b6c16 commit 0a22fed
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/Autofac.Extras.NLog.Tests/ISampleClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public interface ISampleClass
void SampleMessage(string message);
ILogger GetLogger();
}
}
}
2 changes: 1 addition & 1 deletion src/Autofac.Extras.NLog.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<package id="Common.Testing.NUnit" version="1.0.0" targetFramework="net451" userInstalled="true" />
<package id="FluentAssertions" version="3.3.0" targetFramework="net451" userInstalled="true" />
<package id="Moq" version="4.2.1502.0911" targetFramework="net451" userInstalled="true" />
<package id="NLog" version="4.4.1" targetFramework="net451" allowedVersions="[2.0.0, )" userInstalled="true" />
<package id="NLog" version="4.4.1" targetFramework="net451" allowedVersions="[4.3.11, )" userInstalled="true" />
<package id="NUnit" version="2.6.4" targetFramework="net451" userInstalled="true" />
</packages>
110 changes: 109 additions & 1 deletion src/Autofac.Extras.NLog/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,26 @@ public interface ILogger
/// </summary>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="exception">An exception to be logged.</param>
[Obsolete("Use Trace(Exception exception, string message, params object[] args) method instead.")]
void Trace([Localizable(false)] string message, Exception exception);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Trace</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Trace(Exception exception, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Trace</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Trace(Exception exception, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message at the <c>Trace</c> level using the specified parameters and formatting them with the supplied format provider.
/// </summary>
Expand Down Expand Up @@ -335,8 +353,26 @@ public interface ILogger
/// </summary>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="exception">An exception to be logged.</param>
[Obsolete("Use Debug(Exception exception, string message, params object[] args) method instead.")]
void Debug([Localizable(false)] string message, Exception exception);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Debug</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Debug(Exception exception, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Debug</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Debug(Exception exception, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message at the <c>Debug</c> level using the specified parameters and formatting them with the supplied format provider.
/// </summary>
Expand Down Expand Up @@ -444,8 +480,26 @@ public interface ILogger
/// </summary>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="exception">An exception to be logged.</param>
[Obsolete("Use Info(Exception exception, string message, params object[] args) method instead.")]
void Info([Localizable(false)] string message, Exception exception);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Info</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Info(Exception exception, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Info</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Info(Exception exception, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message at the <c>Info</c> level using the specified parameters and formatting them with the supplied format provider.
/// </summary>
Expand Down Expand Up @@ -553,8 +607,26 @@ public interface ILogger
/// </summary>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="exception">An exception to be logged.</param>
[Obsolete("Use Warn(Exception exception, string message, params object[] args) method instead.")]
void Warn([Localizable(false)] string message, Exception exception);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Warn</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Warn(Exception exception, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Warn</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Warn(Exception exception, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message at the <c>Warn</c> level using the specified parameters and formatting them with the supplied format provider.
/// </summary>
Expand Down Expand Up @@ -662,8 +734,26 @@ public interface ILogger
/// </summary>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="exception">An exception to be logged.</param>
[Obsolete("Use Error(Exception exception, string message, params object[] args) method instead.")]
void Error([Localizable(false)] string message, Exception exception);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Error</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Error(Exception exception, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Error</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Error(Exception exception, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message at the <c>Error</c> level using the specified parameters and formatting them with the supplied format provider.
/// </summary>
Expand Down Expand Up @@ -771,8 +861,26 @@ public interface ILogger
/// </summary>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="exception">An exception to be logged.</param>
[Obsolete("Use Fatal(Exception exception, string message, params object[] args) method instead.")]
void Fatal([Localizable(false)] string message, Exception exception);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Fatal</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Fatal(Exception exception, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message and exception at the <c>Fatal</c> level.
/// </summary>
/// <param name="exception">An exception to be logged.</param>
/// <param name="formatProvider">An IFormatProvider that supplies culture-specific formatting information.</param>
/// <param name="message">A <see langword="string" /> to be written.</param>
/// <param name="args">Arguments to format.</param>
void Fatal(Exception exception, IFormatProvider formatProvider, [Localizable(false)] string message, params object[] args);

/// <summary>
/// Writes the diagnostic message at the <c>Fatal</c> level using the specified parameters and formatting them with the supplied format provider.
/// </summary>
Expand Down Expand Up @@ -857,4 +965,4 @@ public interface ILogger
/// <param name="argument3">The third argument to format.</param>
void Fatal<TArgument1, TArgument2, TArgument3>([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3);
}
}
}
64 changes: 62 additions & 2 deletions src/Autofac.Extras.NLog/LoggerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public LoggerAdapter(Logger logger)
remove { _logger.LoggerReconfigured -= value; }
}


public string Name { get { return _logger.Name; } }

public LogFactory Factory { get { return _logger.Factory; } }
Expand Down Expand Up @@ -131,11 +130,22 @@ public void Trace<T>(IFormatProvider formatProvider, T value)
{
_logger.Trace(formatProvider, value);
}

public void Trace(string message, Exception exception)
{
_logger.Trace(exception, message);
}

public void Trace(Exception exception, string message, params object[] args)
{
_logger.Trace(exception, message);
}

public void Trace(Exception exception, IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Trace(exception, formatProvider, message, args);
}

public void Trace(IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Trace(formatProvider, message, args);
Expand Down Expand Up @@ -196,6 +206,16 @@ public void Debug(string message, Exception exception)
_logger.Debug(exception, message);
}

public void Debug(Exception exception, string message, params object[] args)
{
_logger.Debug(exception, message, args);
}

public void Debug(Exception exception, IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Debug(exception, formatProvider, message, args);
}

public void Debug(IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Debug(formatProvider, message, args);
Expand Down Expand Up @@ -256,6 +276,16 @@ public void Info(string message, Exception exception)
_logger.Info(exception, message);
}

public void Info(Exception exception, string message, params object[] args)
{
_logger.Info(exception, message, args);
}

public void Info(Exception exception, IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Info(exception, formatProvider, message, args);
}

public void Info(IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Info(formatProvider, message, args);
Expand Down Expand Up @@ -316,6 +346,16 @@ public void Warn(string message, Exception exception)
_logger.Warn(exception, message);
}

public void Warn(Exception exception, string message, params object[] args)
{
_logger.Warn(exception, message, args);
}

public void Warn(Exception exception, IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Warn(exception, formatProvider, message, args);
}

public void Warn(IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Warn(formatProvider, message, args);
Expand Down Expand Up @@ -376,6 +416,16 @@ public void Error(string message, Exception exception)
_logger.Error(exception, message);
}

public void Error(Exception exception, string message, params object[] args)
{
_logger.Error(exception, message, args);
}

public void Error(Exception exception, IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Error(exception, formatProvider, message, args);
}

public void Error(IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Error(formatProvider, message, args);
Expand Down Expand Up @@ -436,6 +486,16 @@ public void Fatal(string message, Exception exception)
_logger.Fatal(exception,message);
}

public void Fatal(Exception exception, string message, params object[] args)
{
_logger.Fatal(exception, message, args);
}

public void Fatal(Exception exception, IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Fatal(exception, formatProvider, message, args);
}

public void Fatal(IFormatProvider formatProvider, string message, params object[] args)
{
_logger.Fatal(formatProvider, message, args);
Expand Down Expand Up @@ -481,4 +541,4 @@ public void Fatal<TArgument>(string message, TArgument argument)
_logger.Fatal(message, argument1, argument2, argument3);
}
}
}
}
Loading

0 comments on commit 0a22fed

Please sign in to comment.