-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #43 from mscraftsman/logging
Feature suggestion: Add logs with LogLevel using the Standard logging in .NET
Showing
19 changed files
with
293 additions
and
469 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 |
---|---|---|
|
@@ -396,3 +396,4 @@ FodyWeavers.xsd | |
**/appsettings.Development.json | ||
**/client_secret*.json | ||
*.p12 | ||
*.DotSettings |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
1.8.0 | ||
1.8.1 |
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
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
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
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
58 changes: 58 additions & 0 deletions
58
src/Mscc.GenerativeAI/Logging/GenerativeModelLogMessages.cs
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,58 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Mscc.GenerativeAI | ||
{ | ||
#pragma warning disable SYSLIB1006 // Multiple logging methods cannot use the same event id within a class | ||
|
||
/// <summary> | ||
/// Extensions for logging <see cref="GenerativeModel"/> invocations. | ||
/// </summary> | ||
/// <remarks> | ||
/// This extension uses the <see cref="LoggerMessageAttribute"/> to | ||
/// generate logging code at compile time to achieve optimized code. | ||
/// </remarks> | ||
[ExcludeFromCodeCoverage] | ||
internal static partial class GenerativeModelLogMessages | ||
{ | ||
/// <summary> | ||
/// Logs <see cref="GenerativeModel"/> | ||
/// </summary> | ||
/// <param name="logger">Optional. Logger instance used for logging</param> | ||
[LoggerMessage(EventId = 0, Level = LogLevel.Debug, Message = "Generative model starting")] | ||
public static partial void LogGenerativeModelInvoking( | ||
this ILogger logger); | ||
|
||
/// <summary> | ||
/// Logs <see cref="GenerativeModel"/> | ||
/// </summary> | ||
/// <param name="logger">Optional. Logger instance used for logging</param> | ||
[LoggerMessage(EventId = 0, Level = LogLevel.Information, Message = "Generative model started")] | ||
public static partial void LogGenerativeModelInvoked( | ||
this ILogger logger); | ||
|
||
/// <summary> | ||
/// Logs <see cref="GenerativeModel"/> invoking an API request. | ||
/// </summary> | ||
/// <param name="logger">Optional. Logger instance used for logging</param> | ||
/// <param name="methodName">Calling method</param> | ||
/// <param name="url">URL of Gemini API endpoint</param> | ||
/// <param name="payload">Data sent to the API endpoint</param> | ||
[LoggerMessage(EventId = 0, Level = LogLevel.Debug, Message = "[{MethodName}] Request: {Url} - {Payload}")] | ||
public static partial void LogGenerativeModelInvokingRequest( | ||
this ILogger logger, | ||
string methodName, | ||
string url, | ||
string payload); | ||
|
||
/// <summary> | ||
/// Logs <see cref="BaseModel"/> when exception thrown to run an external application. | ||
/// </summary> | ||
/// <param name="logger">Optional. Logger instance used for logging</param> | ||
/// <param name="message">Message of <see cref="System.Exception"/> to log.</param> | ||
[LoggerMessage(EventId = 0, Level = LogLevel.Warning, Message = "{Message}")] | ||
public static partial void LogRunExternalExe( | ||
this ILogger logger, | ||
string message); | ||
} | ||
} |
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
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
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,19 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
|
||
namespace Mscc.GenerativeAI | ||
{ | ||
/// <summary> | ||
/// Abstract base type with logging instance. | ||
/// </summary> | ||
public abstract class BaseLogger | ||
{ | ||
protected ILogger Logger { get; } | ||
|
||
/// <summary> | ||
/// Base constructor to set the <see cref="ILogger"/> instance. | ||
/// </summary> | ||
/// <param name="logger">Optional. Logger instance used for logging</param> | ||
protected BaseLogger(ILogger? logger) => Logger = logger ?? NullLogger.Instance; | ||
} | ||
} |
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
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