2025-09-26 08:05:37 -05:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
2026-02-23 04:05:09 -08:00
|
|
|
namespace Microsoft.CmdPal.Common;
|
2025-09-26 08:05:37 -05:00
|
|
|
|
|
|
|
|
public static class CoreLogger
|
|
|
|
|
{
|
|
|
|
|
public static void InitializeLogger(ILogger implementation)
|
|
|
|
|
{
|
|
|
|
|
_logger = implementation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static ILogger? _logger;
|
|
|
|
|
|
|
|
|
|
public static void LogError(string message, Exception ex, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
|
|
|
|
|
{
|
|
|
|
|
_logger?.LogError(message, ex, memberName, sourceFilePath, sourceLineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogError(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
|
|
|
|
|
{
|
|
|
|
|
_logger?.LogError(message, memberName, sourceFilePath, sourceLineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogWarning(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
|
|
|
|
|
{
|
|
|
|
|
_logger?.LogWarning(message, memberName, sourceFilePath, sourceLineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogInfo(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
|
|
|
|
|
{
|
|
|
|
|
_logger?.LogInfo(message, memberName, sourceFilePath, sourceLineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogDebug(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
|
|
|
|
|
{
|
|
|
|
|
_logger?.LogDebug(message, memberName, sourceFilePath, sourceLineNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LogTrace([System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
|
|
|
|
|
{
|
|
|
|
|
_logger?.LogTrace(memberName, sourceFilePath, sourceLineNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface ILogger
|
|
|
|
|
{
|
|
|
|
|
void LogError(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0);
|
|
|
|
|
|
|
|
|
|
void LogError(string message, Exception ex, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0);
|
|
|
|
|
|
|
|
|
|
void LogWarning(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0);
|
|
|
|
|
|
|
|
|
|
void LogInfo(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0);
|
|
|
|
|
|
|
|
|
|
void LogDebug(string message, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0);
|
|
|
|
|
|
|
|
|
|
void LogTrace([System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0);
|
|
|
|
|
}
|