-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ILogging interface to improve maintenance
- Loading branch information
Showing
8 changed files
with
335 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Diagnostics; | ||
using IOKode.OpinionatedFramework.Facades; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IOKode.OpinionatedFramework.Logging; | ||
|
||
public partial interface ILogging | ||
{ | ||
private ILogger FromCaller() | ||
{ | ||
var callerType = new StackFrame(2).GetMethod()!.DeclaringType!; | ||
|
||
if (callerType == typeof(Log)) // From facade | ||
{ | ||
callerType = new StackFrame(3).GetMethod()!.DeclaringType!; | ||
} | ||
|
||
// Handle the case where the caller is an async state machine | ||
if (callerType is { IsNested: true, DeclaringType: not null } && callerType.Name.Contains('<')) | ||
{ | ||
callerType = callerType.DeclaringType; | ||
} | ||
|
||
var logger = FromCategory(callerType); | ||
|
||
return logger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IOKode.OpinionatedFramework.Logging; | ||
|
||
public partial interface ILogging | ||
{ | ||
/// <summary> | ||
/// Formats and writes a critical log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Critical(EventId eventId, Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Critical, eventId, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a critical log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Critical(EventId eventId, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Critical, eventId, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a critical log message. | ||
/// </summary> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Critical(Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Critical, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a critical log message. | ||
/// </summary> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Critical(string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Critical, message, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IOKode.OpinionatedFramework.Logging; | ||
|
||
public partial interface ILogging | ||
{ | ||
/// <summary> | ||
/// Formats and writes a debug log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Debug(EventId eventId, Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Debug, eventId, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a debug log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Debug(EventId eventId, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Debug, eventId, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a debug log message. | ||
/// </summary> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Debug(Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Debug, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a debug log message. | ||
/// </summary> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Debug(string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Debug, message, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IOKode.OpinionatedFramework.Logging; | ||
|
||
public partial interface ILogging | ||
{ | ||
/// <summary> | ||
/// Formats and writes an error log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Error(EventId eventId, Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Error, eventId, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes an error log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Error(EventId eventId, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Error, eventId, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes an error log message. | ||
/// </summary> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Error(Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Error, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes an error log message. | ||
/// </summary> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Error(string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Error, message, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IOKode.OpinionatedFramework.Logging; | ||
|
||
public partial interface ILogging | ||
{ | ||
/// <summary> | ||
/// Formats and writes an informational log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Info(EventId eventId, Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Information, eventId, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes an informational log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Info(EventId eventId, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Information, eventId, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes an informational log message. | ||
/// </summary> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Info(Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Information, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes an informational log message. | ||
/// </summary> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Info(string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Information, message, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IOKode.OpinionatedFramework.Logging; | ||
|
||
public partial interface ILogging | ||
{ | ||
/// <summary> | ||
/// Formats and writes a trace log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Trace(EventId eventId, Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Trace, eventId, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a trace log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Trace(EventId eventId, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Trace, eventId, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a trace log message. | ||
/// </summary> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Trace(Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Trace, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a trace log message. | ||
/// </summary> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Trace(string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Trace, message, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace IOKode.OpinionatedFramework.Logging; | ||
|
||
public partial interface ILogging | ||
{ | ||
/// <summary> | ||
/// Formats and writes a warning log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Warn(EventId eventId, Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Warning, eventId, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a warning log message. | ||
/// </summary> | ||
/// <param name="eventId">The event id associated with the log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Warn(EventId eventId, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Warning, eventId, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a warning log message. | ||
/// </summary> | ||
/// <param name="exception">The exception to log.</param> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Warn(Exception? exception, string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Warning, exception, message, args); | ||
} | ||
|
||
/// <summary> | ||
/// Formats and writes a warning log message. | ||
/// </summary> | ||
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param> | ||
/// <param name="args">An object array that contains zero or more objects to format.</param> | ||
public void Warn(string? message, params object?[] args) | ||
{ | ||
FromCaller().Log(LogLevel.Warning, message, args); | ||
} | ||
} |
Oops, something went wrong.