From f16345784aaa76e73a796381bd2a17fdb33a7192 Mon Sep 17 00:00:00 2001 From: waldekmastykarz Date: Sun, 16 Nov 2025 17:04:39 +0100 Subject: [PATCH 1/2] Upgrades Dev Proxy to .NET 10. Closes #1445 --- .editorconfig | 2 + .github/workflows/create-release.yml | 6 +- .vscode/launch.json | 4 +- .../DevProxy.Abstractions.csproj | 2 +- .../OllamaLanguageModelClient.cs | 10 +- .../OpenAILanguageModelClient.cs | 10 +- DevProxy.Abstractions/Models/MockResponse.cs | 7 +- DevProxy.Abstractions/Plugins/BaseLoader.cs | 5 +- DevProxy.Abstractions/Plugins/BasePlugin.cs | 5 +- DevProxy.Abstractions/packages.lock.json | 31 +- .../Behavior/GenericErrorResponsesLoader.cs | 5 +- .../Behavior/GenericRandomErrorPlugin.cs | 15 +- DevProxy.Plugins/DevProxy.Plugins.csproj | 2 +- .../Extensions/ApiCenterExtensions.cs | 23 +- .../Extensions/OpenApiDocumentExtensions.cs | 5 +- .../Generation/ApiCenterOnboardingPlugin.cs | 10 +- .../Generation/HarGeneratorPlugin.cs | 2 +- .../Generation/HttpFileGeneratorPlugin.cs | 10 +- .../Generation/MockGeneratorPlugin.cs | 5 +- .../Generation/TypeSpecGeneratorPlugin.cs | 10 +- .../Handlers/TracingDelegatingHandler.cs | 10 +- .../Manipulation/RewritesLoader.cs | 5 +- .../Mocking/CrudApiDefinitionLoader.cs | 5 +- .../Mocking/MockResponsePlugin.cs | 25 +- .../Mocking/MockResponsesLoader.cs | 5 +- DevProxy.Plugins/Reporters/JsonReporter.cs | 5 +- .../Reporters/MarkdownReporter.cs | 5 +- .../Reporters/PlainTextReporter.cs | 5 +- .../ApiCenterMinimalPermissionsPlugin.cs | 97 +++--- .../GraphMinimalPermissionsGuidancePlugin.cs | 30 +- .../GraphMinimalPermissionsPlugin.cs | 15 +- .../Reporting/MinimalCsomPermissionsPlugin.cs | 42 ++- .../MinimalPermissionsGuidancePlugin.cs | 69 ++-- .../Reporting/MinimalPermissionsPlugin.cs | 42 ++- DevProxy.Plugins/Utils/GraphUtils.cs | 10 +- .../Utils/MinimalPermissionsUtils.cs | 5 +- DevProxy.Plugins/packages.lock.json | 81 +---- DevProxy/Commands/ConfigCommand.cs | 15 +- DevProxy/Commands/DevProxyCommand.cs | 8 +- DevProxy/DevProxy.csproj | 7 +- DevProxy/Proxy/ProxyEngine.cs | 11 +- DevProxy/packages.lock.json | 294 +----------------- scripts/local-build.ps1 | 2 +- 43 files changed, 406 insertions(+), 556 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0524a605..dccd2fdd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -236,6 +236,8 @@ dotnet_diagnostic.CA1303.severity = none dotnet_diagnostic.CA1308.severity = none # Avoid uninstantiated internal classes dotnet_diagnostic.CA1812.severity = none +# Avoid potentially expensive logging +dotnet_diagnostic.CA1873.severity = none # Use the LoggerMessage delegates dotnet_diagnostic.CA1848.severity = none # Possible multiple enumerations of IEnumerable collection diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index c01334a1..c8c1a60a 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -59,7 +59,7 @@ jobs: if: matrix.architecture == 'win-x64' run: dotnet build ./DevProxy.Abstractions/DevProxy.Abstractions.csproj -p:InformationalVersion=$("${{ github.ref_name }}".Substring(1)) -c Release --no-self-contained - name: Add plugins to output - run: cp ./DevProxy/bin/Release/net9.0/${{ matrix.architecture }}/plugins ./${{ env.release }} -r + run: cp ./DevProxy/bin/Release/net10.0/${{ matrix.architecture }}/plugins ./${{ env.release }} -r - name: Remove unnecessary files run: | pushd @@ -112,7 +112,7 @@ jobs: shell: pwsh run: > ./sign code azure-key-vault - ./DevProxy.Abstractions/bin/Release/net9.0/DevProxy.Abstractions.dll + ./DevProxy.Abstractions/bin/Release/net10.0/DevProxy.Abstractions.dll --publisher-name "${{ env.APP_PUBLISHER }}" --description "${{ env.APP_DESCRIPTION }}" --description-url "${{ env.APP_DESCRIPTION_URL }}" @@ -127,7 +127,7 @@ jobs: uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 # master with: filename: '../../../../DevProxy.Abstractions-${{ github.ref_name }}.zip' - directory: './DevProxy.Abstractions/bin/Release/net9.0' + directory: './DevProxy.Abstractions/bin/Release/net10.0' exclusions: '*.json' - name: Upload abstractions if: matrix.architecture == 'win-x64' diff --git a/.vscode/launch.json b/.vscode/launch.json index 206ac7b4..9252a22f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,9 +10,9 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/DevProxy/bin/Debug/net9.0/devproxy.dll", + "program": "${workspaceFolder}/DevProxy/bin/Debug/net10.0/devproxy.dll", "args": [], - "cwd": "${workspaceFolder}/DevProxy/bin/Debug/net9.0", + "cwd": "${workspaceFolder}/DevProxy/bin/Debug/net10.0", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console "console": "integratedTerminal", "stopAtEntry": false, diff --git a/DevProxy.Abstractions/DevProxy.Abstractions.csproj b/DevProxy.Abstractions/DevProxy.Abstractions.csproj index ab0d1982..dab9325a 100644 --- a/DevProxy.Abstractions/DevProxy.Abstractions.csproj +++ b/DevProxy.Abstractions/DevProxy.Abstractions.csproj @@ -1,7 +1,7 @@ - net9.0 + net10.0 DevProxy.Abstractions enable enable diff --git a/DevProxy.Abstractions/LanguageModel/OllamaLanguageModelClient.cs b/DevProxy.Abstractions/LanguageModel/OllamaLanguageModelClient.cs index 055ade6f..e6b7377e 100644 --- a/DevProxy.Abstractions/LanguageModel/OllamaLanguageModelClient.cs +++ b/DevProxy.Abstractions/LanguageModel/OllamaLanguageModelClient.cs @@ -54,7 +54,10 @@ public sealed class OllamaLanguageModelClient( if (Configuration.CacheResponses && _cacheChatCompletion.TryGetCacheValue(messages, out var cachedResponse)) { - Logger.LogDebug("Returning cached response for message: {LastMessage}", messages.Last().Content); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("Returning cached response for message: {LastMessage}", messages.Last().Content); + } return cachedResponse; } @@ -181,7 +184,10 @@ protected override async Task IsEnabledCoreAsync(CancellationToken cancell try { var url = $"{Configuration.Url?.TrimEnd('/')}/api/chat"; - Logger.LogDebug("Requesting chat completion. Message: {LastMessage}", messages.Last().Content); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("Requesting chat completion. Message: {LastMessage}", messages.Last().Content); + } var response = await _httpClient.PostAsJsonAsync(url, new diff --git a/DevProxy.Abstractions/LanguageModel/OpenAILanguageModelClient.cs b/DevProxy.Abstractions/LanguageModel/OpenAILanguageModelClient.cs index 7043f145..fb4eed8b 100644 --- a/DevProxy.Abstractions/LanguageModel/OpenAILanguageModelClient.cs +++ b/DevProxy.Abstractions/LanguageModel/OpenAILanguageModelClient.cs @@ -62,7 +62,10 @@ public sealed class OpenAILanguageModelClient( if (Configuration.CacheResponses && _cacheChatCompletion.TryGetCacheValue(messages, out var cachedResponse)) { - _logger.LogDebug("Returning cached response for message: {LastMessage}", messages.Last().Content); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("Returning cached response for message: {LastMessage}", messages.Last().Content); + } return cachedResponse; } @@ -148,7 +151,10 @@ protected override async Task IsEnabledCoreAsync(CancellationToken cancell try { var url = $"{Configuration.Url?.TrimEnd('/')}/chat/completions"; - _logger.LogDebug("Requesting chat completion. Message: {LastMessage}", messages.Last().Content); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("Requesting chat completion. Message: {LastMessage}", messages.Last().Content); + } var payload = new OpenAIChatCompletionRequest { diff --git a/DevProxy.Abstractions/Models/MockResponse.cs b/DevProxy.Abstractions/Models/MockResponse.cs index f5abbed4..5b11034b 100644 --- a/DevProxy.Abstractions/Models/MockResponse.cs +++ b/DevProxy.Abstractions/Models/MockResponse.cs @@ -21,6 +21,8 @@ public object Clone() public static MockResponse FromHttpResponse(string httpResponse, ILogger logger) { + ArgumentNullException.ThrowIfNull(logger); + logger.LogTrace("{Method} called", nameof(FromHttpResponse)); if (string.IsNullOrWhiteSpace(httpResponse)) @@ -40,7 +42,10 @@ public static MockResponse FromHttpResponse(string httpResponse, ILogger logger) for (var i = 0; i < lines.Length; i++) { var line = lines[i]; - logger.LogTrace("Processing line {LineNumber}: {LineContent}", i + 1, line); + if (logger.IsEnabled(LogLevel.Trace)) + { + logger.LogTrace("Processing line {LineNumber}: {LineContent}", i + 1, line); + } if (i == 0) { diff --git a/DevProxy.Abstractions/Plugins/BaseLoader.cs b/DevProxy.Abstractions/Plugins/BaseLoader.cs index bbcada7c..48acda65 100644 --- a/DevProxy.Abstractions/Plugins/BaseLoader.cs +++ b/DevProxy.Abstractions/Plugins/BaseLoader.cs @@ -91,7 +91,10 @@ private async Task ValidateFileContentsAsync(string fileContents, Cancella if (!IsValid) { - Logger.LogError("Schema validation failed for {File} with the following errors: {Errors}", FilePath, string.Join(", ", ValidationErrors)); + if (Logger.IsEnabled(LogLevel.Error)) + { + Logger.LogError("Schema validation failed for {File} with the following errors: {Errors}", FilePath, string.Join(", ", ValidationErrors)); + } } return IsValid; diff --git a/DevProxy.Abstractions/Plugins/BasePlugin.cs b/DevProxy.Abstractions/Plugins/BasePlugin.cs index d093f9da..0c92438b 100644 --- a/DevProxy.Abstractions/Plugins/BasePlugin.cs +++ b/DevProxy.Abstractions/Plugins/BasePlugin.cs @@ -110,7 +110,10 @@ public override async Task InitializeAsync(InitArgs e, CancellationToken cancell var (IsValid, ValidationErrors) = await ValidatePluginConfigAsync(cancellationToken); if (!IsValid) { - Logger.LogError("Plugin configuration validation failed with the following errors: {Errors}", string.Join(", ", ValidationErrors)); + if (Logger.IsEnabled(LogLevel.Error)) + { + Logger.LogError("Plugin configuration validation failed with the following errors: {Errors}", string.Join(", ", ValidationErrors)); + } } } diff --git a/DevProxy.Abstractions/packages.lock.json b/DevProxy.Abstractions/packages.lock.json index af377dc9..06dbd97e 100644 --- a/DevProxy.Abstractions/packages.lock.json +++ b/DevProxy.Abstractions/packages.lock.json @@ -1,7 +1,7 @@ { "version": 1, "dependencies": { - "net9.0": { + "net10.0": { "Markdig": { "type": "Direct", "requested": "[0.41.3, )", @@ -20,8 +20,7 @@ "Microsoft.Extensions.DependencyModel": "9.0.4", "Microsoft.Extensions.Logging": "9.0.4", "SQLitePCLRaw.bundle_e_sqlite3": "2.1.10", - "SQLitePCLRaw.core": "2.1.10", - "System.Text.Json": "9.0.4" + "SQLitePCLRaw.core": "2.1.10" } }, "Microsoft.Extensions.Configuration": { @@ -102,8 +101,7 @@ "contentHash": "HiICGm0e44+i4aVHpLn+aphmSC2eQnDvlTttw1rE0hntOZKoLGRy37sydqqbRP1ZokMf3Mt0GEgSWxDwnucKGg==", "dependencies": { "BouncyCastle.Cryptography": "2.4.0", - "Microsoft.Extensions.Logging.Abstractions": "8.0.1", - "System.Runtime.CompilerServices.Unsafe": "6.0.0" + "Microsoft.Extensions.Logging.Abstractions": "8.0.1" } }, "YamlDotNet": { @@ -168,8 +166,7 @@ "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", "Microsoft.Extensions.DependencyModel": "9.0.4", "Microsoft.Extensions.Logging": "9.0.4", - "SQLitePCLRaw.core": "2.1.10", - "System.Text.Json": "9.0.4" + "SQLitePCLRaw.core": "2.1.10" } }, "Microsoft.Extensions.Caching.Abstractions": { @@ -304,10 +301,7 @@ "SQLitePCLRaw.core": { "type": "Transitive", "resolved": "2.1.10", - "contentHash": "Ii8JCbC7oiVclaE/mbDEK000EFIJ+ShRPwAvvV89GOZhQ+ZLtlnSWl6ksCNMKu/VGXA4Nfi2B7LhN/QFN9oBcw==", - "dependencies": { - "System.Memory": "4.5.3" - } + "contentHash": "Ii8JCbC7oiVclaE/mbDEK000EFIJ+ShRPwAvvV89GOZhQ+ZLtlnSWl6ksCNMKu/VGXA4Nfi2B7LhN/QFN9oBcw==" }, "SQLitePCLRaw.lib.e_sqlite3": { "type": "Transitive", @@ -321,21 +315,6 @@ "dependencies": { "SQLitePCLRaw.core": "2.1.10" } - }, - "System.Memory": { - "type": "Transitive", - "resolved": "4.5.3", - "contentHash": "3oDzvc/zzetpTKWMShs1AADwZjQ/36HnsufHRPcOjyRAAMLDlu2iD33MBI2opxnezcVUtXyqDXXjoFMOU9c7SA==" - }, - "System.Runtime.CompilerServices.Unsafe": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" - }, - "System.Text.Json": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "pYtmpcO6R3Ef1XilZEHgXP2xBPVORbYEzRP7dl0IAAbN8Dm+kfwio8aCKle97rAWXOExr292MuxWYurIuwN62g==" } } } diff --git a/DevProxy.Plugins/Behavior/GenericErrorResponsesLoader.cs b/DevProxy.Plugins/Behavior/GenericErrorResponsesLoader.cs index 7f8cf22c..a37d14aa 100644 --- a/DevProxy.Plugins/Behavior/GenericErrorResponsesLoader.cs +++ b/DevProxy.Plugins/Behavior/GenericErrorResponsesLoader.cs @@ -30,7 +30,10 @@ protected override void LoadData(string fileContents) if (configResponses is not null) { _configuration.Errors = configResponses; - Logger.LogInformation("{ConfigResponseCount} error responses loaded from {ErrorFile}", configResponses.Count(), _configuration.ErrorsFile); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("{ConfigResponseCount} error responses loaded from {ErrorFile}", configResponses.Count(), _configuration.ErrorsFile); + } } } catch (Exception ex) diff --git a/DevProxy.Plugins/Behavior/GenericRandomErrorPlugin.cs b/DevProxy.Plugins/Behavior/GenericRandomErrorPlugin.cs index 96c37658..f7b67e4c 100644 --- a/DevProxy.Plugins/Behavior/GenericRandomErrorPlugin.cs +++ b/DevProxy.Plugins/Behavior/GenericRandomErrorPlugin.cs @@ -308,12 +308,15 @@ private void ValidateErrors() } var suggestedWildcards = ProxyUtils.GetWildcardPatterns(unmatchedErrorUrls.AsReadOnly()); - Logger.LogWarning( - "The following URLs in {ErrorsFile} don't match any URL to watch: {UnmatchedMocks}. Add the following URLs to URLs to watch: {UrlsToWatch}", - Configuration.ErrorsFile, - string.Join(", ", unmatchedErrorUrls), - string.Join(", ", suggestedWildcards) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "The following URLs in {ErrorsFile} don't match any URL to watch: {UnmatchedMocks}. Add the following URLs to URLs to watch: {UrlsToWatch}", + Configuration.ErrorsFile, + string.Join(", ", unmatchedErrorUrls), + string.Join(", ", suggestedWildcards) + ); + } } private static bool HasMatchingBody(GenericErrorResponse errorResponse, Request request) diff --git a/DevProxy.Plugins/DevProxy.Plugins.csproj b/DevProxy.Plugins/DevProxy.Plugins.csproj index e5c66e2a..537a3096 100644 --- a/DevProxy.Plugins/DevProxy.Plugins.csproj +++ b/DevProxy.Plugins/DevProxy.Plugins.csproj @@ -1,6 +1,6 @@  - net9.0 + net10.0 DevProxy.Plugins enable enable diff --git a/DevProxy.Plugins/Extensions/ApiCenterExtensions.cs b/DevProxy.Plugins/Extensions/ApiCenterExtensions.cs index a387970d..979b6fa2 100644 --- a/DevProxy.Plugins/Extensions/ApiCenterExtensions.cs +++ b/DevProxy.Plugins/Extensions/ApiCenterExtensions.cs @@ -129,11 +129,14 @@ internal static async Task> GetApiDefinitionsB } } - logger.LogDebug( - "Loaded API definitions from API Center for APIs:{NewLine}- {Apis}", - Environment.NewLine, - string.Join($"{Environment.NewLine}- ", apiDefinitions.Keys) - ); + if (logger.IsEnabled(LogLevel.Debug)) + { + logger.LogDebug( + "Loaded API definitions from API Center for APIs:{NewLine}- {Apis}", + Environment.NewLine, + string.Join($"{Environment.NewLine}- ", apiDefinitions.Keys) + ); + } return apiDefinitions; } @@ -165,7 +168,10 @@ internal static IEnumerable GetUrls(this Api api) if (api.Versions.Length == 1) { - logger.LogDebug("API {Api} has only one version {Version}. Returning", api.Name, api.Versions[0].Name); + if (logger.IsEnabled(LogLevel.Debug)) + { + logger.LogDebug("API {Api} has only one version {Version}. Returning", api.Name, api.Versions[0].Name); + } return api.Versions[0]; } @@ -198,7 +204,10 @@ internal static IEnumerable GetUrls(this Api api) ); if (header is not null) { - logger.LogDebug("Version {Version} found in header {Header}", $"{apiVersion.Name}/{apiVersion.Properties?.Title}", header.Name); + if (logger.IsEnabled(LogLevel.Debug)) + { + logger.LogDebug("Version {Version} found in header {Header}", $"{apiVersion.Name}/{apiVersion.Properties?.Title}", header.Name); + } return apiVersion; } } diff --git a/DevProxy.Plugins/Extensions/OpenApiDocumentExtensions.cs b/DevProxy.Plugins/Extensions/OpenApiDocumentExtensions.cs index 2a4fbbd8..8adfc6c7 100644 --- a/DevProxy.Plugins/Extensions/OpenApiDocumentExtensions.cs +++ b/DevProxy.Plugins/Extensions/OpenApiDocumentExtensions.cs @@ -18,7 +18,10 @@ static class OpenApiDocumentExtensions public static ApiPermissionsInfo CheckMinimalPermissions(this OpenApiDocument openApiDocument, IEnumerable requests, ILogger logger, string? schemeName = default) { - logger.LogInformation("Checking minimal permissions for API {ApiName}...", openApiDocument.Servers.First().Url); + if (logger.IsEnabled(LogLevel.Information)) + { + logger.LogInformation("Checking minimal permissions for API {ApiName}...", openApiDocument.Servers.First().Url); + } var tokenPermissions = new List(); var operationsFromRequests = new List(); diff --git a/DevProxy.Plugins/Generation/ApiCenterOnboardingPlugin.cs b/DevProxy.Plugins/Generation/ApiCenterOnboardingPlugin.cs index 090cb88f..23e26124 100644 --- a/DevProxy.Plugins/Generation/ApiCenterOnboardingPlugin.cs +++ b/DevProxy.Plugins/Generation/ApiCenterOnboardingPlugin.cs @@ -211,7 +211,10 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation newApisMessageChunks.AddRange(apiPerHost.Select(a => $" {a.method} {a.url}")); } - Logger.LogInformation("{NewApis}", string.Join(Environment.NewLine, newApisMessageChunks)); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("{NewApis}", string.Join(Environment.NewLine, newApisMessageChunks)); + } if (!Configuration.CreateApicEntryForNewApis) { @@ -328,7 +331,10 @@ async Task CreateApisInApiCenterAsync( } else { - Logger.LogError("Failed to create API version for {Api}", apiId[apiId.LastIndexOf('/')..]); + if (Logger.IsEnabled(LogLevel.Error)) + { + Logger.LogError("Failed to create API version for {Api}", apiId[apiId.LastIndexOf('/')..]); + } } return newApiVersion; diff --git a/DevProxy.Plugins/Generation/HarGeneratorPlugin.cs b/DevProxy.Plugins/Generation/HarGeneratorPlugin.cs index 766ef525..584e1119 100644 --- a/DevProxy.Plugins/Generation/HarGeneratorPlugin.cs +++ b/DevProxy.Plugins/Generation/HarGeneratorPlugin.cs @@ -113,7 +113,7 @@ private HarEntry CreateHarEntry(RequestLog log) QueryString = [.. HttpUtility.ParseQueryString(request.RequestUri?.Query ?? "") .AllKeys .Where(key => key is not null) - .Select(key => new HarQueryParam { Name = key!, Value = HttpUtility.ParseQueryString(request.RequestUri?.Query ?? "")[key] ?? "" })], + .Select(key => new HarQueryParam { Name = key, Value = HttpUtility.ParseQueryString(request.RequestUri?.Query ?? "")[key] ?? "" })], Cookies = [.. request.Headers .Where(h => string.Equals(h.Name, "Cookie", StringComparison.OrdinalIgnoreCase)) .Select(h => h.Value) diff --git a/DevProxy.Plugins/Generation/HttpFileGeneratorPlugin.cs b/DevProxy.Plugins/Generation/HttpFileGeneratorPlugin.cs index f37decd8..302b435b 100644 --- a/DevProxy.Plugins/Generation/HttpFileGeneratorPlugin.cs +++ b/DevProxy.Plugins/Generation/HttpFileGeneratorPlugin.cs @@ -231,7 +231,10 @@ private void ExtractVariables(HttpFile httpFile) var headers = request.Headers.Where(h => h.Name.Contains(headerName, StringComparison.OrdinalIgnoreCase)); if (headers is not null) { - Logger.LogDebug(" Found {NumHeaders} matching headers...", headers.Count()); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug(" Found {NumHeaders} matching headers...", headers.Count()); + } foreach (var header in headers) { @@ -256,7 +259,10 @@ private void ExtractVariables(HttpFile httpFile) var queryParams = query.AllKeys.Where(k => k is not null && k.Contains(queryParameterName, StringComparison.OrdinalIgnoreCase)); if (queryParams is not null) { - Logger.LogDebug(" Found {NumQueryParams} matching query parameters...", queryParams.Count()); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug(" Found {NumQueryParams} matching query parameters...", queryParams.Count()); + } foreach (var queryParam in queryParams) { diff --git a/DevProxy.Plugins/Generation/MockGeneratorPlugin.cs b/DevProxy.Plugins/Generation/MockGeneratorPlugin.cs index 27bad69d..7ed8b64c 100644 --- a/DevProxy.Plugins/Generation/MockGeneratorPlugin.cs +++ b/DevProxy.Plugins/Generation/MockGeneratorPlugin.cs @@ -93,7 +93,10 @@ request.Context.Session is null || Logger.LogDebug("Writing mocks to {FileName}...", fileName); await File.WriteAllTextAsync(fileName, mocksFileJson, cancellationToken); - Logger.LogInformation("Created mock file {FileName} with {MocksCount} mocks", fileName, mocks.Count); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Created mock file {FileName} with {MocksCount} mocks", fileName, mocks.Count); + } StoreReport(fileName, e); diff --git a/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs b/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs index eb35f989..b85d8c0d 100644 --- a/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs +++ b/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs @@ -226,12 +226,18 @@ private void AddAuthorizationAuth(Operation op, string bearerToken, TypeSpecFile .SelectMany(c => c.Value.Split(' ', StringSplitOptions.RemoveEmptyEntries)) .Distinct() .ToList(); - Logger.LogDebug("Scopes: {Scopes}", string.Join(", ", scopes)); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("Scopes: {Scopes}", string.Join(", ", scopes)); + } var roles = jwtToken.Claims .Where(c => c.Type == "roles") .SelectMany(c => c.Value.Split(' ', StringSplitOptions.RemoveEmptyEntries)) .Distinct(); - Logger.LogDebug("Roles: {Roles}", string.Join(", ", roles)); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("Roles: {Roles}", string.Join(", ", roles)); + } scopes.AddRange(roles); OAuth2Auth? auth = null; diff --git a/DevProxy.Plugins/Handlers/TracingDelegatingHandler.cs b/DevProxy.Plugins/Handlers/TracingDelegatingHandler.cs index 66774571..640aa358 100644 --- a/DevProxy.Plugins/Handlers/TracingDelegatingHandler.cs +++ b/DevProxy.Plugins/Handlers/TracingDelegatingHandler.cs @@ -18,7 +18,10 @@ protected override async Task SendAsync(HttpRequestMessage _logger.LogTrace("Request: {Method} {Uri}", request.Method, request.RequestUri); foreach (var (header, value) in request.Headers) { - _logger.LogTrace("{Header}: {Value}", header, string.Join(", ", value)); + if (_logger.IsEnabled(LogLevel.Trace)) + { + _logger.LogTrace("{Header}: {Value}", header, string.Join(", ", value)); + } } if (request.Content is not null) { @@ -31,7 +34,10 @@ protected override async Task SendAsync(HttpRequestMessage _logger.LogTrace("Response"); foreach (var (header, value) in response.Headers) { - _logger.LogTrace("{Header}: {Value}", header, string.Join(", ", value)); + if (_logger.IsEnabled(LogLevel.Trace)) + { + _logger.LogTrace("{Header}: {Value}", header, string.Join(", ", value)); + } } if (response.Content is not null) { diff --git a/DevProxy.Plugins/Manipulation/RewritesLoader.cs b/DevProxy.Plugins/Manipulation/RewritesLoader.cs index 3558d3f8..09526f0b 100644 --- a/DevProxy.Plugins/Manipulation/RewritesLoader.cs +++ b/DevProxy.Plugins/Manipulation/RewritesLoader.cs @@ -30,7 +30,10 @@ protected override void LoadData(string fileContents) if (configRewrites is not null) { _configuration.Rewrites = configRewrites; - Logger.LogInformation("Rewrites for {ConfigResponseCount} url patterns loaded from {RewritesFile}", configRewrites.Count(), _configuration.RewritesFile); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Rewrites for {ConfigResponseCount} url patterns loaded from {RewritesFile}", configRewrites.Count(), _configuration.RewritesFile); + } } } catch (Exception ex) diff --git a/DevProxy.Plugins/Mocking/CrudApiDefinitionLoader.cs b/DevProxy.Plugins/Mocking/CrudApiDefinitionLoader.cs index 60889a56..9f9c5c96 100644 --- a/DevProxy.Plugins/Mocking/CrudApiDefinitionLoader.cs +++ b/DevProxy.Plugins/Mocking/CrudApiDefinitionLoader.cs @@ -52,7 +52,10 @@ protected override void LoadData(string fileContents) }; } } - Logger.LogInformation("{ConfigResponseCount} actions for CRUD API loaded from {ApiFile}", configResponses.Count(), _configuration.ApiFile); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("{ConfigResponseCount} actions for CRUD API loaded from {ApiFile}", configResponses.Count(), _configuration.ApiFile); + } } } catch (Exception ex) diff --git a/DevProxy.Plugins/Mocking/MockResponsePlugin.cs b/DevProxy.Plugins/Mocking/MockResponsePlugin.cs index 69c2d1f6..6df8d23a 100644 --- a/DevProxy.Plugins/Mocking/MockResponsePlugin.cs +++ b/DevProxy.Plugins/Mocking/MockResponsePlugin.cs @@ -273,12 +273,15 @@ private void ValidateMocks() } var suggestedWildcards = ProxyUtils.GetWildcardPatterns(unmatchedMockUrls.AsReadOnly()); - Logger.LogWarning( - "The following URLs in {MocksFile} don't match any URL to watch: {UnmatchedMocks}. Add the following URLs to URLs to watch: {UrlsToWatch}", - Configuration.MocksFile, - string.Join(", ", unmatchedMockUrls), - string.Join(", ", suggestedWildcards) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "The following URLs in {MocksFile} don't match any URL to watch: {UnmatchedMocks}. Add the following URLs to URLs to watch: {UrlsToWatch}", + Configuration.MocksFile, + string.Join(", ", unmatchedMockUrls), + string.Join(", ", suggestedWildcards) + ); + } } private MockResponse? GetMatchingMockResponse(Request request) @@ -461,8 +464,14 @@ private async Task GenerateMocksFromHttpResponsesAsync(ParseResult parseResult) return; } - Logger.LogInformation("Found {FileCount} matching HTTP response files", matchingFiles.Count()); - Logger.LogDebug("Matching files: {Files}", string.Join(", ", matchingFiles)); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Found {FileCount} matching HTTP response files", matchingFiles.Count()); + } + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("Matching files: {Files}", string.Join(", ", matchingFiles)); + } var mockResponses = new List(); foreach (var file in matchingFiles) diff --git a/DevProxy.Plugins/Mocking/MockResponsesLoader.cs b/DevProxy.Plugins/Mocking/MockResponsesLoader.cs index be461810..8a9d31fa 100644 --- a/DevProxy.Plugins/Mocking/MockResponsesLoader.cs +++ b/DevProxy.Plugins/Mocking/MockResponsesLoader.cs @@ -30,7 +30,10 @@ protected override void LoadData(string fileContents) if (configResponses is not null) { _configuration.Mocks = configResponses; - Logger.LogInformation("Mock responses for {ConfigResponseCount} url patterns loaded from {MockFile}", configResponses.Count(), _configuration.MocksFile); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Mock responses for {ConfigResponseCount} url patterns loaded from {MockFile}", configResponses.Count(), _configuration.MocksFile); + } } } catch (Exception ex) diff --git a/DevProxy.Plugins/Reporters/JsonReporter.cs b/DevProxy.Plugins/Reporters/JsonReporter.cs index 8bc79b30..716053f1 100644 --- a/DevProxy.Plugins/Reporters/JsonReporter.cs +++ b/DevProxy.Plugins/Reporters/JsonReporter.cs @@ -32,7 +32,10 @@ protected override string GetReport(KeyValuePair report) } else { - Logger.LogDebug("No transformer found for {ReportType}", reportData.GetType().Name); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("No transformer found for {ReportType}", reportData.GetType().Name); + } } if (reportData is string strVal) diff --git a/DevProxy.Plugins/Reporters/MarkdownReporter.cs b/DevProxy.Plugins/Reporters/MarkdownReporter.cs index fb9e9069..5e8f130e 100644 --- a/DevProxy.Plugins/Reporters/MarkdownReporter.cs +++ b/DevProxy.Plugins/Reporters/MarkdownReporter.cs @@ -26,7 +26,10 @@ public class MarkdownReporter( } else { - Logger.LogDebug("No transformer found for {ReportType}", reportData.GetType().Name); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("No transformer found for {ReportType}", reportData.GetType().Name); + } return null; } } diff --git a/DevProxy.Plugins/Reporters/PlainTextReporter.cs b/DevProxy.Plugins/Reporters/PlainTextReporter.cs index d5d51681..0ec0490f 100644 --- a/DevProxy.Plugins/Reporters/PlainTextReporter.cs +++ b/DevProxy.Plugins/Reporters/PlainTextReporter.cs @@ -26,7 +26,10 @@ public class PlainTextReporter( } else { - Logger.LogDebug("No transformer found for {ReportType}", reportData.GetType().Name); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("No transformer found for {ReportType}", reportData.GetType().Name); + } return null; } } diff --git a/DevProxy.Plugins/Reporting/ApiCenterMinimalPermissionsPlugin.cs b/DevProxy.Plugins/Reporting/ApiCenterMinimalPermissionsPlugin.cs index 9a5223b3..47c31d88 100644 --- a/DevProxy.Plugins/Reporting/ApiCenterMinimalPermissionsPlugin.cs +++ b/DevProxy.Plugins/Reporting/ApiCenterMinimalPermissionsPlugin.cs @@ -159,63 +159,81 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation { if (string.IsNullOrWhiteSpace(Configuration.SchemeName)) { - Logger.LogInformation( - "API {ApiName} is called with minimal permissions: {MinimalPermissions}", - result.ApiName, - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation( + "API {ApiName} is called with minimal permissions: {MinimalPermissions}", + result.ApiName, + string.Join(", ", result.MinimalPermissions) + ); + } } else { - Logger.LogInformation( - "API {ApiName} is called with minimal permissions of '{SchemeName}' scheme: {MinimalPermissions}", - result.ApiName, - Configuration.SchemeName, - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation( + "API {ApiName} is called with minimal permissions of '{SchemeName}' scheme: {MinimalPermissions}", + result.ApiName, + Configuration.SchemeName, + string.Join(", ", result.MinimalPermissions) + ); + } } } else { if (string.IsNullOrWhiteSpace(Configuration.SchemeName)) { - Logger.LogWarning( - "Calling API {ApiName} with excessive permissions: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", - result.ApiName, - string.Join(", ", result.ExcessivePermissions), - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Calling API {ApiName} with excessive permissions: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", + result.ApiName, + string.Join(", ", result.ExcessivePermissions), + string.Join(", ", result.MinimalPermissions) + ); + } } else { - Logger.LogWarning( - "Calling API {ApiName} with excessive permissions of '{SchemeName}' scheme: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", - result.ApiName, - Configuration.SchemeName, - string.Join(", ", result.ExcessivePermissions), - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Calling API {ApiName} with excessive permissions of '{SchemeName}' scheme: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", + result.ApiName, + Configuration.SchemeName, + string.Join(", ", result.ExcessivePermissions), + string.Join(", ", result.MinimalPermissions) + ); + } } } if (unmatchedApiRequests.Any()) { - Logger.LogWarning( - "Unmatched requests for API {ApiName}:{NewLine}- {UnmatchedRequests}", - result.ApiName, - Environment.NewLine, - string.Join($"{Environment.NewLine}- ", unmatchedApiRequests) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Unmatched requests for API {ApiName}:{NewLine}- {UnmatchedRequests}", + result.ApiName, + Environment.NewLine, + string.Join($"{Environment.NewLine}- ", unmatchedApiRequests) + ); + } } if (minimalPermissions.Errors.Any()) { - Logger.LogWarning( - "Errors for API {ApiName}:{NewLine}- {Errors}", - result.ApiName, - Environment.NewLine, - string.Join($"{Environment.NewLine}- ", minimalPermissions.Errors.Select(e => $"{e.Request}: {e.Error}")) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Errors for API {ApiName}:{NewLine}- {Errors}", + result.ApiName, + Environment.NewLine, + string.Join($"{Environment.NewLine}- ", minimalPermissions.Errors.Select(e => $"{e.Request}: {e.Error}")) + ); + } } } @@ -233,9 +251,12 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation private ApiPermissionsInfo CheckMinimalPermissions(IEnumerable requests, ApiDefinition apiDefinition) { - Logger.LogInformation("Checking minimal permissions for API {ApiName}...", apiDefinition.Definition!.Servers.First().Url); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Checking minimal permissions for API {ApiName}...", apiDefinition.Definition!.Servers.First().Url); + } - return apiDefinition.Definition.CheckMinimalPermissions(requests, Logger, Configuration.SchemeName); + return apiDefinition.Definition!.CheckMinimalPermissions(requests, Logger, Configuration.SchemeName); } private (Dictionary> RequestsByApiDefinition, IEnumerable UnmatchedRequests) GetRequestsByApiDefinition(IEnumerable interceptedRequests, Dictionary apiDefinitionsByUrl) diff --git a/DevProxy.Plugins/Reporting/GraphMinimalPermissionsGuidancePlugin.cs b/DevProxy.Plugins/Reporting/GraphMinimalPermissionsGuidancePlugin.cs index 1a89224d..5b66185c 100644 --- a/DevProxy.Plugins/Reporting/GraphMinimalPermissionsGuidancePlugin.cs +++ b/DevProxy.Plugins/Reporting/GraphMinimalPermissionsGuidancePlugin.cs @@ -175,7 +175,8 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation Logger.LogWarning("This plugin is in preview and may not return the correct results.\r\nPlease review the permissions and test your app before using them in production.\r\nIf you have any feedback, please open an issue at https://aka.ms/devproxy/issue.\r\n"); - if (Configuration.PermissionsToExclude?.Any() == true) + if (Configuration.PermissionsToExclude?.Any() == true && + Logger.IsEnabled(LogLevel.Information)) { Logger.LogInformation("Excluding the following permissions: {Permissions}", string.Join(", ", Configuration.PermissionsToExclude)); } @@ -185,7 +186,10 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation var delegatedPermissionsInfo = new GraphMinimalPermissionsInfo(); report.DelegatedPermissions = delegatedPermissionsInfo; - Logger.LogInformation("Evaluating delegated permissions for: {Endpoints}", string.Join(", ", delegatedEndpoints.Select(e => $"{e.Method} {e.Url}"))); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Evaluating delegated permissions for: {Endpoints}", string.Join(", ", delegatedEndpoints.Select(e => $"{e.Method} {e.Url}"))); + } await EvaluateMinimalScopesAsync(delegatedEndpoints, scopesToEvaluate, GraphPermissionsType.Delegated, delegatedPermissionsInfo, cancellationToken); } @@ -195,7 +199,10 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation var applicationPermissionsInfo = new GraphMinimalPermissionsInfo(); report.ApplicationPermissions = applicationPermissionsInfo; - Logger.LogInformation("Evaluating application permissions for: {Endpoints}", string.Join(", ", applicationEndpoints.Select(e => $"{e.Method} {e.Url}"))); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Evaluating application permissions for: {Endpoints}", string.Join(", ", applicationEndpoints.Select(e => $"{e.Method} {e.Url}"))); + } await EvaluateMinimalScopesAsync(applicationEndpoints, rolesToEvaluate, GraphPermissionsType.Application, applicationPermissionsInfo, cancellationToken); } @@ -264,12 +271,18 @@ private async Task EvaluateMinimalScopesAsync( permissionsInfo.MinimalPermissions = minimalPermissions; permissionsInfo.ExcessPermissions = excessPermissions; - Logger.LogInformation("Minimal permissions: {MinimalPermissions}", string.Join(", ", minimalPermissions)); - Logger.LogInformation("Permissions on the token: {TokenPermissions}", string.Join(", ", permissionsFromAccessToken)); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Minimal permissions: {MinimalPermissions}", string.Join(", ", minimalPermissions)); + Logger.LogInformation("Permissions on the token: {TokenPermissions}", string.Join(", ", permissionsFromAccessToken)); + } if (excessPermissions.Any()) { - Logger.LogWarning("The following permissions are unnecessary: {Permissions}", string.Join(", ", excessPermissions)); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning("The following permissions are unnecessary: {Permissions}", string.Join(", ", excessPermissions)); + } } else { @@ -278,7 +291,10 @@ private async Task EvaluateMinimalScopesAsync( } if (errors.Any()) { - Logger.LogError("Couldn't determine minimal permissions for the following URLs: {Errors}", string.Join(", ", errors)); + if (Logger.IsEnabled(LogLevel.Error)) + { + Logger.LogError("Couldn't determine minimal permissions for the following URLs: {Errors}", string.Join(", ", errors)); + } } } catch (Exception ex) diff --git a/DevProxy.Plugins/Reporting/GraphMinimalPermissionsPlugin.cs b/DevProxy.Plugins/Reporting/GraphMinimalPermissionsPlugin.cs index f20855b9..71c55a77 100644 --- a/DevProxy.Plugins/Reporting/GraphMinimalPermissionsPlugin.cs +++ b/DevProxy.Plugins/Reporting/GraphMinimalPermissionsPlugin.cs @@ -109,7 +109,10 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation return; } - Logger.LogInformation("Retrieving minimal permissions for:\r\n{Endpoints}\r\n", string.Join(Environment.NewLine, endpoints.Select(e => $"- {e.Method} {e.Url}"))); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Retrieving minimal permissions for:\r\n{Endpoints}\r\n", string.Join(Environment.NewLine, endpoints.Select(e => $"- {e.Method} {e.Url}"))); + } Logger.LogWarning("This plugin is in preview and may not return the correct results.\r\nPlease review the permissions and test your app before using them in production.\r\nIf you have any feedback, please open an issue at https://aka.ms/devproxy/issue.\r\n"); @@ -155,11 +158,17 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation if (minimalScopes.Any()) { - Logger.LogInformation("Minimal permissions:\r\n{Permissions}", string.Join(", ", minimalScopes)); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Minimal permissions:\r\n{Permissions}", string.Join(", ", minimalScopes)); + } } if (errors.Any()) { - Logger.LogError("Couldn't determine minimal permissions for the following URLs:\r\n{Errors}", string.Join(Environment.NewLine, errors)); + if (Logger.IsEnabled(LogLevel.Error)) + { + Logger.LogError("Couldn't determine minimal permissions for the following URLs:\r\n{Errors}", string.Join(Environment.NewLine, errors)); + } } return new() diff --git a/DevProxy.Plugins/Reporting/MinimalCsomPermissionsPlugin.cs b/DevProxy.Plugins/Reporting/MinimalCsomPermissionsPlugin.cs index 7dfd89c2..ffcfdba6 100644 --- a/DevProxy.Plugins/Reporting/MinimalCsomPermissionsPlugin.cs +++ b/DevProxy.Plugins/Reporting/MinimalCsomPermissionsPlugin.cs @@ -111,13 +111,16 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation var (requestActions, requestErrors) = CsomParser.GetActions(requestBody, Configuration.TypesDefinitions!); - Logger.LogDebug("Actions: {Actions}", string.Join(", ", requestActions)); - Logger.LogDebug("Errors: {Errors}", string.Join(", ", requestErrors)); + if (Logger.IsEnabled(LogLevel.Debug)) + { + Logger.LogDebug("Actions: {Actions}", string.Join(", ", requestActions)); + Logger.LogDebug("Errors: {Errors}", string.Join(", ", requestErrors)); + } actions.AddRange(requestActions); errors.AddRange(requestErrors); - if (requestErrors.Any()) + if (requestErrors.Any() && Logger.IsEnabled(LogLevel.Error)) { Logger.LogError( "The following errors occurred while parsing CSOM:{NewLine}{Errors}", @@ -133,26 +136,35 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation return; } - Logger.LogInformation( - "Detected {Count} CSOM actions:{NewLine}{Actions}", - actions.Count, - Environment.NewLine, - string.Join(Environment.NewLine, actions.Select(a => $"- {a}")) - ); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation( + "Detected {Count} CSOM actions:{NewLine}{Actions}", + actions.Count, + Environment.NewLine, + string.Join(Environment.NewLine, actions.Select(a => $"- {a}")) + ); + } var (minimalScopes, scopesErrors) = CsomParser.GetMinimalScopes(actions, AccessType.Delegated, Configuration.TypesDefinitions!); if (scopesErrors.Any()) { errors.AddRange(scopesErrors); - Logger.LogError( - "The following errors occurred while getting minimal scopes:{NewLine}{Errors}", - Environment.NewLine, - string.Join(Environment.NewLine, scopesErrors.Select(e => $"- {e}")) - ); + if (Logger.IsEnabled(LogLevel.Error)) + { + Logger.LogError( + "The following errors occurred while getting minimal scopes:{NewLine}{Errors}", + Environment.NewLine, + string.Join(Environment.NewLine, scopesErrors.Select(e => $"- {e}")) + ); + } } - Logger.LogInformation("Minimal permissions: {MinimalScopes}", string.Join(", ", minimalScopes)); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Minimal permissions: {MinimalScopes}", string.Join(", ", minimalScopes)); + } var report = new MinimalCsomPermissionsPluginReport() { diff --git a/DevProxy.Plugins/Reporting/MinimalPermissionsGuidancePlugin.cs b/DevProxy.Plugins/Reporting/MinimalPermissionsGuidancePlugin.cs index 71b4a338..090f831c 100644 --- a/DevProxy.Plugins/Reporting/MinimalPermissionsGuidancePlugin.cs +++ b/DevProxy.Plugins/Reporting/MinimalPermissionsGuidancePlugin.cs @@ -116,46 +116,59 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation { if (string.IsNullOrWhiteSpace(Configuration.SchemeName)) { - Logger.LogInformation( - "API {ApiName} is called with minimal permissions: {MinimalPermissions}", - result.ApiName, - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation( + "API {ApiName} is called with minimal permissions: {MinimalPermissions}", + result.ApiName, + string.Join(", ", result.MinimalPermissions) + ); + } } else { - Logger.LogInformation( - "API {ApiName} is called with minimal permissions of '{SchemeName}' scheme: {MinimalPermissions}", - result.ApiName, - Configuration.SchemeName, - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation( + "API {ApiName} is called with minimal permissions of '{SchemeName}' scheme: {MinimalPermissions}", + result.ApiName, + Configuration.SchemeName, + string.Join(", ", result.MinimalPermissions) + ); + } } } else { if (string.IsNullOrWhiteSpace(Configuration.SchemeName)) { - Logger.LogWarning( - "Calling API {ApiName} with excessive permissions: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", - result.ApiName, - string.Join(", ", result.ExcessivePermissions), - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Calling API {ApiName} with excessive permissions: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", + result.ApiName, + string.Join(", ", result.ExcessivePermissions), + string.Join(", ", result.MinimalPermissions) + ); + } } else { - Logger.LogWarning( - "Calling API {ApiName} with excessive permissions of '{SchemeName}' scheme: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", - result.ApiName, - Configuration.SchemeName, - string.Join(", ", result.ExcessivePermissions), - string.Join(", ", result.MinimalPermissions) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Calling API {ApiName} with excessive permissions of '{SchemeName}' scheme: {ExcessivePermissions}. Minimal permissions are: {MinimalPermissions}", + result.ApiName, + Configuration.SchemeName, + string.Join(", ", result.ExcessivePermissions), + string.Join(", ", result.MinimalPermissions) + ); + } } } - if (unmatchedApiRequests.Any()) + if (unmatchedApiRequests.Any() && + Logger.IsEnabled(LogLevel.Warning)) { Logger.LogWarning( "Unmatched requests for API {ApiName}:{NewLine}- {UnmatchedRequests}", @@ -165,7 +178,8 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation ); } - if (minimalPermissions.Errors.Any()) + if (minimalPermissions.Errors.Any() && + Logger.IsEnabled(LogLevel.Warning)) { Logger.LogWarning( "Errors for API {ApiName}:{NewLine}- {Errors}", @@ -184,7 +198,8 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation ExcludedPermissions = Configuration.PermissionsToExclude }; - if (Configuration.PermissionsToExclude?.Any() == true) + if (Configuration.PermissionsToExclude?.Any() == true && + Logger.IsEnabled(LogLevel.Information)) { Logger.LogInformation("Excluding the following permissions: {Permissions}", string.Join(", ", Configuration.PermissionsToExclude)); } diff --git a/DevProxy.Plugins/Reporting/MinimalPermissionsPlugin.cs b/DevProxy.Plugins/Reporting/MinimalPermissionsPlugin.cs index d3d8c760..9e1dfbfe 100644 --- a/DevProxy.Plugins/Reporting/MinimalPermissionsPlugin.cs +++ b/DevProxy.Plugins/Reporting/MinimalPermissionsPlugin.cs @@ -116,32 +116,44 @@ public override async Task AfterRecordingStopAsync(RecordingArgs e, Cancellation if (unmatchedApiRequests.Any()) { - Logger.LogWarning( - "Unmatched requests for API {ApiName}:{NewLine}- {UnmatchedRequests}", - result.ApiName, - Environment.NewLine, - string.Join($"{Environment.NewLine}- ", unmatchedApiRequests) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Unmatched requests for API {ApiName}:{NewLine}- {UnmatchedRequests}", + result.ApiName, + Environment.NewLine, + string.Join($"{Environment.NewLine}- ", unmatchedApiRequests) + ); + } } if (minimalPermissions.Errors.Any()) { - Logger.LogWarning( - "Errors for API {ApiName}:{NewLine}- {Errors}", - result.ApiName, - Environment.NewLine, - string.Join($"{Environment.NewLine}- ", minimalPermissions.Errors.Select(e => $"{e.Request}: {e.Error}")) - ); + if (Logger.IsEnabled(LogLevel.Warning)) + { + Logger.LogWarning( + "Errors for API {ApiName}:{NewLine}- {Errors}", + result.ApiName, + Environment.NewLine, + string.Join($"{Environment.NewLine}- ", minimalPermissions.Errors.Select(e => $"{e.Request}: {e.Error}")) + ); + } } if (string.IsNullOrWhiteSpace(Configuration.SchemeName)) { - Logger.LogInformation("Minimal permissions: {MinimalScopes}", string.Join(", ", result.MinimalPermissions)); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Minimal permissions: {MinimalScopes}", string.Join(", ", result.MinimalPermissions)); + } } else { - Logger.LogInformation("Minimal permissions of '{SchemeName}' scheme: {MinimalScopes}", - Configuration.SchemeName, string.Join(", ", result.MinimalPermissions)); + if (Logger.IsEnabled(LogLevel.Information)) + { + Logger.LogInformation("Minimal permissions of '{SchemeName}' scheme: {MinimalScopes}", + Configuration.SchemeName, string.Join(", ", result.MinimalPermissions)); + } } } diff --git a/DevProxy.Plugins/Utils/GraphUtils.cs b/DevProxy.Plugins/Utils/GraphUtils.cs index 986f708e..04b7ac17 100644 --- a/DevProxy.Plugins/Utils/GraphUtils.cs +++ b/DevProxy.Plugins/Utils/GraphUtils.cs @@ -89,13 +89,19 @@ internal async Task> UpdateUserScopesAsync(IEnumerable c.Value) .ToArray() ?? []; - logger.LogDebug("Scopes found in the token: {Scopes}", string.Join(", ", scopes)); + if (logger.IsEnabled(LogLevel.Debug)) + { + logger.LogDebug("Scopes found in the token: {Scopes}", string.Join(", ", scopes)); + } return scopes; } catch (Exception ex) diff --git a/DevProxy.Plugins/packages.lock.json b/DevProxy.Plugins/packages.lock.json index 10eb0fc6..3455a5aa 100644 --- a/DevProxy.Plugins/packages.lock.json +++ b/DevProxy.Plugins/packages.lock.json @@ -1,7 +1,7 @@ { "version": 1, "dependencies": { - "net9.0": { + "net10.0": { "Azure.Identity": { "type": "Direct", "requested": "[1.13.2, )", @@ -10,9 +10,7 @@ "dependencies": { "Azure.Core": "1.44.1", "Microsoft.Identity.Client": "4.67.2", - "Microsoft.Identity.Client.Extensions.Msal": "4.67.2", - "System.Memory": "4.5.5", - "System.Threading.Tasks.Extensions": "4.5.4" + "Microsoft.Identity.Client.Extensions.Msal": "4.67.2" } }, "Microsoft.EntityFrameworkCore.Sqlite": { @@ -27,8 +25,7 @@ "Microsoft.Extensions.DependencyModel": "9.0.4", "Microsoft.Extensions.Logging": "9.0.4", "SQLitePCLRaw.bundle_e_sqlite3": "2.1.10", - "SQLitePCLRaw.core": "2.1.10", - "System.Text.Json": "9.0.4" + "SQLitePCLRaw.core": "2.1.10" } }, "Microsoft.Extensions.Configuration": { @@ -112,8 +109,7 @@ "contentHash": "HiICGm0e44+i4aVHpLn+aphmSC2eQnDvlTttw1rE0hntOZKoLGRy37sydqqbRP1ZokMf3Mt0GEgSWxDwnucKGg==", "dependencies": { "BouncyCastle.Cryptography": "2.4.0", - "Microsoft.Extensions.Logging.Abstractions": "8.0.1", - "System.Runtime.CompilerServices.Unsafe": "6.0.0" + "Microsoft.Extensions.Logging.Abstractions": "8.0.1" } }, "Azure.Core": { @@ -123,12 +119,7 @@ "dependencies": { "Microsoft.Bcl.AsyncInterfaces": "6.0.0", "System.ClientModel": "1.1.0", - "System.Diagnostics.DiagnosticSource": "6.0.1", - "System.Memory.Data": "6.0.0", - "System.Numerics.Vectors": "4.5.0", - "System.Text.Encodings.Web": "6.0.0", - "System.Text.Json": "6.0.10", - "System.Threading.Tasks.Extensions": "4.5.4" + "System.Memory.Data": "6.0.0" } }, "BouncyCastle.Cryptography": { @@ -197,8 +188,7 @@ "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", "Microsoft.Extensions.DependencyModel": "9.0.4", "Microsoft.Extensions.Logging": "9.0.4", - "SQLitePCLRaw.core": "2.1.10", - "System.Text.Json": "9.0.4" + "SQLitePCLRaw.core": "2.1.10" } }, "Microsoft.Extensions.Caching.Abstractions": { @@ -369,8 +359,7 @@ "resolved": "4.67.2", "contentHash": "37t0TfekfG6XM8kue/xNaA66Qjtti5Qe1xA41CK+bEd8VD76/oXJc+meFJHGzygIC485dCpKoamG/pDfb9Qd7Q==", "dependencies": { - "Microsoft.IdentityModel.Abstractions": "6.35.0", - "System.Diagnostics.DiagnosticSource": "6.0.1" + "Microsoft.IdentityModel.Abstractions": "6.35.0" } }, "Microsoft.Identity.Client.Extensions.Msal": { @@ -440,10 +429,7 @@ "OpenTelemetry.Api": { "type": "Transitive", "resolved": "1.12.0", - "contentHash": "Xt0qldi+iE2szGrM3jAqzEMEJd48YBtqI6mge0+ArXTZg3aTpRmyhL6CKKl3bLioaFSSVbBpEbPin8u6Z46Yrw==", - "dependencies": { - "System.Diagnostics.DiagnosticSource": "9.0.0" - } + "contentHash": "Xt0qldi+iE2szGrM3jAqzEMEJd48YBtqI6mge0+ArXTZg3aTpRmyhL6CKKl3bLioaFSSVbBpEbPin8u6Z46Yrw==" }, "OpenTelemetry.Api.ProviderBuilderExtensions": { "type": "Transitive", @@ -476,10 +462,7 @@ "SQLitePCLRaw.core": { "type": "Transitive", "resolved": "2.1.10", - "contentHash": "Ii8JCbC7oiVclaE/mbDEK000EFIJ+ShRPwAvvV89GOZhQ+ZLtlnSWl6ksCNMKu/VGXA4Nfi2B7LhN/QFN9oBcw==", - "dependencies": { - "System.Memory": "4.5.3" - } + "contentHash": "Ii8JCbC7oiVclaE/mbDEK000EFIJ+ShRPwAvvV89GOZhQ+ZLtlnSWl6ksCNMKu/VGXA4Nfi2B7LhN/QFN9oBcw==" }, "SQLitePCLRaw.lib.e_sqlite3": { "type": "Transitive", @@ -499,61 +482,19 @@ "resolved": "1.1.0", "contentHash": "UocOlCkxLZrG2CKMAAImPcldJTxeesHnHGHwhJ0pNlZEvEXcWKuQvVOER2/NiOkJGRJk978SNdw3j6/7O9H1lg==", "dependencies": { - "System.Memory.Data": "1.0.2", - "System.Text.Json": "6.0.9" + "System.Memory.Data": "1.0.2" } }, - "System.Diagnostics.DiagnosticSource": { - "type": "Transitive", - "resolved": "9.0.0", - "contentHash": "ddppcFpnbohLWdYKr/ZeLZHmmI+DXFgZ3Snq+/E7SwcdW4UnvxmaugkwGywvGVWkHPGCSZjCP+MLzu23AL5SDw==" - }, - "System.Memory": { - "type": "Transitive", - "resolved": "4.5.5", - "contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==" - }, "System.Memory.Data": { "type": "Transitive", "resolved": "6.0.0", - "contentHash": "ntFHArH3I4Lpjf5m4DCXQHJuGwWPNVJPaAvM95Jy/u+2Yzt2ryiyIN04LAogkjP9DeRcEOiviAjQotfmPq/FrQ==", - "dependencies": { - "System.Text.Json": "6.0.0" - } - }, - "System.Numerics.Vectors": { - "type": "Transitive", - "resolved": "4.5.0", - "contentHash": "QQTlPTl06J/iiDbJCiepZ4H//BVraReU4O4EoRw1U02H5TLUIT7xn3GnDp9AXPSlJUDyFs4uWjWafNX6WrAojQ==" - }, - "System.Runtime.CompilerServices.Unsafe": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" + "contentHash": "ntFHArH3I4Lpjf5m4DCXQHJuGwWPNVJPaAvM95Jy/u+2Yzt2ryiyIN04LAogkjP9DeRcEOiviAjQotfmPq/FrQ==" }, "System.Security.Cryptography.ProtectedData": { "type": "Transitive", "resolved": "4.5.0", "contentHash": "wLBKzFnDCxP12VL9ANydSYhk59fC4cvOr9ypYQLPnAj48NQIhqnjdD2yhP8yEKyBJEjERWS9DisKL7rX5eU25Q==" }, - "System.Text.Encodings.Web": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "Vg8eB5Tawm1IFqj4TVK1czJX89rhFxJo9ELqc/Eiq0eXy13RK00eubyU6TJE6y+GQXjyV5gSfiewDUZjQgSE0w==", - "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0" - } - }, - "System.Text.Json": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "pYtmpcO6R3Ef1XilZEHgXP2xBPVORbYEzRP7dl0IAAbN8Dm+kfwio8aCKle97rAWXOExr292MuxWYurIuwN62g==" - }, - "System.Threading.Tasks.Extensions": { - "type": "Transitive", - "resolved": "4.5.4", - "contentHash": "zteT+G8xuGu6mS+mzDzYXbzS7rd3K6Fjb9RiZlYlJPam2/hU7JCBZBVEcywNuR+oZ1ncTvc/cq0faRr3P01OVg==" - }, "YamlDotNet": { "type": "Transitive", "resolved": "16.3.0", diff --git a/DevProxy/Commands/ConfigCommand.cs b/DevProxy/Commands/ConfigCommand.cs index 478c68bc..a089494b 100644 --- a/DevProxy/Commands/ConfigCommand.cs +++ b/DevProxy/Commands/ConfigCommand.cs @@ -158,7 +158,10 @@ private async Task DownloadConfigAsync(string configId) _logger.LogInformation("To start Dev Proxy with the config, run:"); foreach (var configFile in configInfo.ConfigFiles) { - _logger.LogInformation(" devproxy --config-file \"{ConfigFile}\"", configFile.Replace(appFolder, "~appFolder", StringComparison.OrdinalIgnoreCase)); + if (_logger.IsEnabled(LogLevel.Information)) + { + _logger.LogInformation(" devproxy --config-file \"{ConfigFile}\"", configFile.Replace(appFolder, "~appFolder", StringComparison.OrdinalIgnoreCase)); + } } } else @@ -166,7 +169,10 @@ private async Task DownloadConfigAsync(string configId) _logger.LogInformation("To start Dev Proxy with the mock file, enable the MockResponsePlugin or GraphMockResponsePlugin and run:"); foreach (var mockFile in configInfo.MockFiles) { - _logger.LogInformation(" devproxy --mock-file \"{MockFile}\"", mockFile.Replace(appFolder, "~appFolder", StringComparison.OrdinalIgnoreCase)); + if (_logger.IsEnabled(LogLevel.Information)) + { + _logger.LogInformation(" devproxy --mock-file \"{MockFile}\"", mockFile.Replace(appFolder, "~appFolder", StringComparison.OrdinalIgnoreCase)); + } } } } @@ -227,7 +233,10 @@ private ProxyConfigInfo GetConfigInfo(string configFolder) if (configInfo.ConfigFiles.Any()) { - _logger.LogDebug("Found {ConfigFilesCount} proxy config files. Clearing mocks...", configInfo.ConfigFiles.Count); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("Found {ConfigFilesCount} proxy config files. Clearing mocks...", configInfo.ConfigFiles.Count); + } configInfo.MockFiles.Clear(); } diff --git a/DevProxy/Commands/DevProxyCommand.cs b/DevProxy/Commands/DevProxyCommand.cs index 55bdc0ae..b581b54a 100644 --- a/DevProxy/Commands/DevProxyCommand.cs +++ b/DevProxy/Commands/DevProxyCommand.cs @@ -35,21 +35,21 @@ sealed class DevProxyCommand : RootCommand private static readonly string[] helpOptions = ["--help", "-h", "/h", "-?", "/?"]; private static bool _hasGlobalOptionsResolved; - private static bool _hasGlobalOptions; + public static bool HasGlobalOptions { get { if (_hasGlobalOptionsResolved) { - return _hasGlobalOptions; + return field; } var args = Environment.GetCommandLineArgs(); - _hasGlobalOptions = args.Any(arg => globalOptions.Contains(arg)) || + field = args.Any(arg => globalOptions.Contains(arg)) || args.Any(arg => helpOptions.Contains(arg)); _hasGlobalOptionsResolved = true; - return _hasGlobalOptions; + return field; } } diff --git a/DevProxy/DevProxy.csproj b/DevProxy/DevProxy.csproj index abbf8678..e12d9985 100644 --- a/DevProxy/DevProxy.csproj +++ b/DevProxy/DevProxy.csproj @@ -2,7 +2,7 @@ Exe - net9.0 + net10.0 DevProxy enable enable @@ -34,11 +34,6 @@ - - - - - diff --git a/DevProxy/Proxy/ProxyEngine.cs b/DevProxy/Proxy/ProxyEngine.cs index 04c1498c..9d355263 100755 --- a/DevProxy/Proxy/ProxyEngine.cs +++ b/DevProxy/Proxy/ProxyEngine.cs @@ -458,10 +458,13 @@ private bool IsIncludedByHeaders(HeaderCollection requestHeaders) foreach (var header in _config.FilterByHeaders) { - _logger.LogDebug("Checking header {Header} with value {Value}...", - header.Name, - string.IsNullOrEmpty(header.Value) ? "(any)" : header.Value - ); + if (_logger.IsEnabled(LogLevel.Debug)) + { + _logger.LogDebug("Checking header {Header} with value {Value}...", + header.Name, + string.IsNullOrEmpty(header.Value) ? "(any)" : header.Value + ); + } if (requestHeaders.HeaderExists(header.Name)) { diff --git a/DevProxy/packages.lock.json b/DevProxy/packages.lock.json index 69c28690..d55e4a3e 100644 --- a/DevProxy/packages.lock.json +++ b/DevProxy/packages.lock.json @@ -1,7 +1,7 @@ { "version": 1, "dependencies": { - "net9.0": { + "net10.0": { "Azure.Identity": { "type": "Direct", "requested": "[1.13.2, )", @@ -10,9 +10,7 @@ "dependencies": { "Azure.Core": "1.44.1", "Microsoft.Identity.Client": "4.67.2", - "Microsoft.Identity.Client.Extensions.Msal": "4.67.2", - "System.Memory": "4.5.5", - "System.Threading.Tasks.Extensions": "4.5.4" + "Microsoft.Identity.Client.Extensions.Msal": "4.67.2" } }, "Microsoft.EntityFrameworkCore.Sqlite": { @@ -22,63 +20,9 @@ "contentHash": "YruNASPuiCjLOVxO09lpQT4e2OYvpsoD0e5NGEQKOcPCu143RDzWTNlpzcxhArBgAS0FPwQ+OEGZOWhwgWHvOA==", "dependencies": { "Microsoft.EntityFrameworkCore.Sqlite.Core": "9.0.4", - "Microsoft.Extensions.Caching.Memory": "9.0.4", - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", "Microsoft.Extensions.DependencyModel": "9.0.4", - "Microsoft.Extensions.Logging": "9.0.4", "SQLitePCLRaw.bundle_e_sqlite3": "2.1.10", - "SQLitePCLRaw.core": "2.1.10", - "System.Text.Json": "9.0.4" - } - }, - "Microsoft.Extensions.Configuration": { - "type": "Direct", - "requested": "[9.0.4, )", - "resolved": "9.0.4", - "contentHash": "KIVBrMbItnCJDd1RF4KEaE8jZwDJcDUJW5zXpbwQ05HNYTK1GveHxHK0B3SjgDJuR48GRACXAO+BLhL8h34S7g==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.Configuration.Binder": { - "type": "Direct", - "requested": "[9.0.4, )", - "resolved": "9.0.4", - "contentHash": "cdrjcl9RIcwt3ECbnpP0Gt1+pkjdW90mq5yFYy8D9qRj2NqFFcv3yDp141iEamsd9E218sGxK8WHaIOcrqgDJg==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4" - } - }, - "Microsoft.Extensions.Configuration.Json": { - "type": "Direct", - "requested": "[9.0.4, )", - "resolved": "9.0.4", - "contentHash": "vVXI70CgT/dmXV3MM+n/BR2rLXEoAyoK0hQT+8MrbCMuJBiLRxnTtSrksNiASWCwOtxo/Tyy7CO8AGthbsYxnw==", - "dependencies": { - "Microsoft.Extensions.Configuration": "9.0.4", - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", - "Microsoft.Extensions.Configuration.FileExtensions": "9.0.4", - "Microsoft.Extensions.FileProviders.Abstractions": "9.0.4" - } - }, - "Microsoft.Extensions.FileSystemGlobbing": { - "type": "Direct", - "requested": "[9.0.6, )", - "resolved": "9.0.6", - "contentHash": "1HJCAbwukNEoYbHgHbKHmenU0V/0huw8+i7Qtf5rLUG1E+3kEwRJQxpwD3wbTEagIgPSQisNgJTvmUX9yYVc6g==" - }, - "Microsoft.Extensions.Logging.Console": { - "type": "Direct", - "requested": "[9.0.4, )", - "resolved": "9.0.4", - "contentHash": "cI0lQe0js65INCTCtAgnlVJWKgzgoRHVAW1B1zwCbmcliO4IZoTf92f1SYbLeLk7FzMJ/GlCvjLvJegJ6kltmQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.4", - "Microsoft.Extensions.Logging": "9.0.4", - "Microsoft.Extensions.Logging.Abstractions": "9.0.4", - "Microsoft.Extensions.Logging.Configuration": "9.0.4", - "Microsoft.Extensions.Options": "9.0.4" + "SQLitePCLRaw.core": "2.1.10" } }, "Microsoft.IdentityModel.Protocols.OpenIdConnect": { @@ -124,8 +68,6 @@ "resolved": "1.12.0", "contentHash": "aIEu2O3xFOdwIVH0AJsIHPIMH1YuX18nzu7BHyaDNQ6NWSk4Zyrs9Pp6y8SATuSbvdtmvue4mj/QZ3838srbwA==", "dependencies": { - "Microsoft.Extensions.Diagnostics.Abstractions": "9.0.0", - "Microsoft.Extensions.Logging.Configuration": "9.0.0", "OpenTelemetry.Api.ProviderBuilderExtensions": "1.12.0" } }, @@ -172,9 +114,7 @@ "resolved": "0.1.5", "contentHash": "HiICGm0e44+i4aVHpLn+aphmSC2eQnDvlTttw1rE0hntOZKoLGRy37sydqqbRP1ZokMf3Mt0GEgSWxDwnucKGg==", "dependencies": { - "BouncyCastle.Cryptography": "2.4.0", - "Microsoft.Extensions.Logging.Abstractions": "8.0.1", - "System.Runtime.CompilerServices.Unsafe": "6.0.0" + "BouncyCastle.Cryptography": "2.4.0" } }, "Azure.Core": { @@ -184,12 +124,7 @@ "dependencies": { "Microsoft.Bcl.AsyncInterfaces": "6.0.0", "System.ClientModel": "1.1.0", - "System.Diagnostics.DiagnosticSource": "6.0.1", - "System.Memory.Data": "6.0.0", - "System.Numerics.Vectors": "4.5.0", - "System.Text.Encodings.Web": "6.0.0", - "System.Text.Json": "6.0.10", - "System.Threading.Tasks.Extensions": "4.5.4" + "System.Memory.Data": "6.0.0" } }, "BouncyCastle.Cryptography": { @@ -221,9 +156,7 @@ "contentHash": "+5IAX0aicQYCRfN4pAjad+JPwdEYoVEM3Z1Cl8/EiEv3FVHQHdd8TJQpQIslQDDQS/UsUMb0MsOXwqOh+TJtRw==", "dependencies": { "Microsoft.EntityFrameworkCore.Abstractions": "9.0.4", - "Microsoft.EntityFrameworkCore.Analyzers": "9.0.4", - "Microsoft.Extensions.Caching.Memory": "9.0.4", - "Microsoft.Extensions.Logging": "9.0.4" + "Microsoft.EntityFrameworkCore.Analyzers": "9.0.4" } }, "Microsoft.EntityFrameworkCore.Abstractions": { @@ -241,10 +174,7 @@ "resolved": "9.0.4", "contentHash": "OjJ+xh/wQff5b0wiC3SPvoQqTA2boZeJQf+15+3+OJPtjBKzvxuwr25QRIu1p1t+K8ryQ8pzaoZ7eOpXfNzVGA==", "dependencies": { - "Microsoft.EntityFrameworkCore": "9.0.4", - "Microsoft.Extensions.Caching.Memory": "9.0.4", - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", - "Microsoft.Extensions.Logging": "9.0.4" + "Microsoft.EntityFrameworkCore": "9.0.4" } }, "Microsoft.EntityFrameworkCore.Sqlite.Core": { @@ -254,12 +184,8 @@ "dependencies": { "Microsoft.Data.Sqlite.Core": "9.0.4", "Microsoft.EntityFrameworkCore.Relational": "9.0.4", - "Microsoft.Extensions.Caching.Memory": "9.0.4", - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", "Microsoft.Extensions.DependencyModel": "9.0.4", - "Microsoft.Extensions.Logging": "9.0.4", - "SQLitePCLRaw.core": "2.1.10", - "System.Text.Json": "9.0.4" + "SQLitePCLRaw.core": "2.1.10" } }, "Microsoft.Extensions.ApiDescription.Server": { @@ -267,157 +193,17 @@ "resolved": "6.0.5", "contentHash": "Ckb5EDBUNJdFWyajfXzUIMRkhf52fHZOQuuZg/oiu8y7zDCVwD0iHhew6MnThjHmevanpxL3f5ci2TtHQEN6bw==" }, - "Microsoft.Extensions.Caching.Abstractions": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "imcZ5BGhBw5mNsWLepBbqqumWaFe0GtvyCvne2/2wsDIBRa2+Lhx4cU/pKt/4BwOizzUEOls2k1eOJQXHGMalg==", - "dependencies": { - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.Caching.Memory": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "G5rEq1Qez5VJDTEyRsRUnewAspKjaY57VGsdZ8g8Ja6sXXzoiI3PpTd1t43HjHqNWD5A06MQveb2lscn+2CU+w==", - "dependencies": { - "Microsoft.Extensions.Caching.Abstractions": "9.0.4", - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.4", - "Microsoft.Extensions.Logging.Abstractions": "9.0.4", - "Microsoft.Extensions.Options": "9.0.4", - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.Configuration.Abstractions": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "0LN/DiIKvBrkqp7gkF3qhGIeZk6/B63PthAHjQsxymJfIBcz0kbf4/p/t4lMgggVxZ+flRi5xvTwlpPOoZk8fg==", - "dependencies": { - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.Configuration.FileExtensions": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "UY864WQ3AS2Fkc8fYLombWnjrXwYt+BEHHps0hY4sxlgqaVW06AxbpgRZjfYf8PyRbplJqruzZDB/nSLT+7RLQ==", - "dependencies": { - "Microsoft.Extensions.Configuration": "9.0.4", - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", - "Microsoft.Extensions.FileProviders.Abstractions": "9.0.4", - "Microsoft.Extensions.FileProviders.Physical": "9.0.4", - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.DependencyInjection": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "f2MTUaS2EQ3lX4325ytPAISZqgBfXmY0WvgD80ji6Z20AoDNiCESxsqo6mFRwHJD/jfVKRw9FsW6+86gNre3ug==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.4" - } - }, - "Microsoft.Extensions.DependencyInjection.Abstractions": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "UI0TQPVkS78bFdjkTodmkH0Fe8lXv9LnhGFKgKrsgUJ5a5FVdFRcgjIkBVLbGgdRhxWirxH/8IXUtEyYJx6GQg==" - }, "Microsoft.Extensions.DependencyModel": { "type": "Transitive", "resolved": "9.0.4", "contentHash": "ACtnvl3H3M/f8Z42980JxsNu7V9PPbzys4vBs83ZewnsgKd7JeYK18OMPo0g+MxAHrpgMrjmlinXDiaSRPcVnA==" }, - "Microsoft.Extensions.Diagnostics.Abstractions": { - "type": "Transitive", - "resolved": "9.0.0", - "contentHash": "1K8P7XzuzX8W8pmXcZjcrqS6x5eSSdvhQohmcpgiQNY/HlDAlnrhR9dvlURfFz428A+RTCJpUyB+aKTA6AgVcQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0", - "Microsoft.Extensions.Options": "9.0.0" - } - }, - "Microsoft.Extensions.FileProviders.Abstractions": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "gQN2o/KnBfVk6Bd71E2YsvO5lsqrqHmaepDGk+FB/C4aiQY9B0XKKNKfl5/TqcNOs9OEithm4opiMHAErMFyEw==", - "dependencies": { - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.FileProviders.Physical": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "qkQ9V7KFZdTWNThT7ke7E/Jad38s46atSs3QUYZB8f3thBTrcrousdY4Y/tyCtcH5YjsPSiByjuN+L8W/ThMQg==", - "dependencies": { - "Microsoft.Extensions.FileProviders.Abstractions": "9.0.4", - "Microsoft.Extensions.FileSystemGlobbing": "9.0.4", - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.Logging": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "xW6QPYsqhbuWBO9/1oA43g/XPKbohJx+7G8FLQgQXIriYvY7s+gxr2wjQJfRoPO900dvvv2vVH7wZovG+M1m6w==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection": "9.0.4", - "Microsoft.Extensions.Logging.Abstractions": "9.0.4", - "Microsoft.Extensions.Options": "9.0.4" - } - }, - "Microsoft.Extensions.Logging.Abstractions": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "0MXlimU4Dud6t+iNi5NEz3dO2w1HXdhoOLaYFuLPCjAsvlPQGwOT6V2KZRMLEhCAm/stSZt1AUv0XmDdkjvtbw==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.4" - } - }, - "Microsoft.Extensions.Logging.Configuration": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "/kF+rSnoo3/nIwGzWsR4RgBnoTOdZ3lzz2qFRyp/GgaNid4j6hOAQrs/O+QHXhlcAdZxjg37MvtIE+pAvIgi9g==", - "dependencies": { - "Microsoft.Extensions.Configuration": "9.0.4", - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", - "Microsoft.Extensions.Configuration.Binder": "9.0.4", - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.4", - "Microsoft.Extensions.Logging": "9.0.4", - "Microsoft.Extensions.Logging.Abstractions": "9.0.4", - "Microsoft.Extensions.Options": "9.0.4", - "Microsoft.Extensions.Options.ConfigurationExtensions": "9.0.4" - } - }, - "Microsoft.Extensions.Options": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "fiFI2+58kicqVZyt/6obqoFwHiab7LC4FkQ3mmiBJ28Yy4fAvy2+v9MRnSvvlOO8chTOjKsdafFl/K9veCPo5g==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.4", - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.Options.ConfigurationExtensions": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "aridVhAT3Ep+vsirR1pzjaOw0Jwiob6dc73VFQn2XmDfBA2X98M8YKO1GarvsXRX7gX1Aj+hj2ijMzrMHDOm0A==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "9.0.4", - "Microsoft.Extensions.Configuration.Binder": "9.0.4", - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.4", - "Microsoft.Extensions.Options": "9.0.4", - "Microsoft.Extensions.Primitives": "9.0.4" - } - }, - "Microsoft.Extensions.Primitives": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "SPFyMjyku1nqTFFJ928JAMd0QnRe4xjE7KeKnZMWXf3xk+6e0WiOZAluYtLdbJUXtsl2cCRSi8cBquJ408k8RA==" - }, "Microsoft.Identity.Client": { "type": "Transitive", "resolved": "4.67.2", "contentHash": "37t0TfekfG6XM8kue/xNaA66Qjtti5Qe1xA41CK+bEd8VD76/oXJc+meFJHGzygIC485dCpKoamG/pDfb9Qd7Q==", "dependencies": { - "Microsoft.IdentityModel.Abstractions": "6.35.0", - "System.Diagnostics.DiagnosticSource": "6.0.1" + "Microsoft.IdentityModel.Abstractions": "6.35.0" } }, "Microsoft.Identity.Client.Extensions.Msal": { @@ -463,7 +249,6 @@ "resolved": "8.9.0", "contentHash": "qK6kW5qZvDj7E5RLWQ9gzJxQe5GUz7+7bXrLQQydSDF9hTf5Ip2qHuAQW3Fg9GND6jkjTr7IXAZFmBHadNQi4Q==", "dependencies": { - "Microsoft.Extensions.Logging.Abstractions": "8.0.2", "Microsoft.IdentityModel.Logging": "8.9.0" } }, @@ -501,17 +286,13 @@ "OpenTelemetry.Api": { "type": "Transitive", "resolved": "1.12.0", - "contentHash": "Xt0qldi+iE2szGrM3jAqzEMEJd48YBtqI6mge0+ArXTZg3aTpRmyhL6CKKl3bLioaFSSVbBpEbPin8u6Z46Yrw==", - "dependencies": { - "System.Diagnostics.DiagnosticSource": "9.0.0" - } + "contentHash": "Xt0qldi+iE2szGrM3jAqzEMEJd48YBtqI6mge0+ArXTZg3aTpRmyhL6CKKl3bLioaFSSVbBpEbPin8u6Z46Yrw==" }, "OpenTelemetry.Api.ProviderBuilderExtensions": { "type": "Transitive", "resolved": "1.12.0", "contentHash": "t6Vk1143BfiisCWYbRcyzkAuN6Aq5RkYtfOSMoqCIRMvtN9p1e1xzc0nWQ+fccNGOVgHn3aMK5xFn2+iWMcr8A==", "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0", "OpenTelemetry.Api": "1.12.0" } }, @@ -537,10 +318,7 @@ "SQLitePCLRaw.core": { "type": "Transitive", "resolved": "2.1.10", - "contentHash": "Ii8JCbC7oiVclaE/mbDEK000EFIJ+ShRPwAvvV89GOZhQ+ZLtlnSWl6ksCNMKu/VGXA4Nfi2B7LhN/QFN9oBcw==", - "dependencies": { - "System.Memory": "4.5.3" - } + "contentHash": "Ii8JCbC7oiVclaE/mbDEK000EFIJ+ShRPwAvvV89GOZhQ+ZLtlnSWl6ksCNMKu/VGXA4Nfi2B7LhN/QFN9oBcw==" }, "SQLitePCLRaw.lib.e_sqlite3": { "type": "Transitive", @@ -581,61 +359,19 @@ "resolved": "1.1.0", "contentHash": "UocOlCkxLZrG2CKMAAImPcldJTxeesHnHGHwhJ0pNlZEvEXcWKuQvVOER2/NiOkJGRJk978SNdw3j6/7O9H1lg==", "dependencies": { - "System.Memory.Data": "1.0.2", - "System.Text.Json": "6.0.9" + "System.Memory.Data": "1.0.2" } }, - "System.Diagnostics.DiagnosticSource": { - "type": "Transitive", - "resolved": "9.0.0", - "contentHash": "ddppcFpnbohLWdYKr/ZeLZHmmI+DXFgZ3Snq+/E7SwcdW4UnvxmaugkwGywvGVWkHPGCSZjCP+MLzu23AL5SDw==" - }, - "System.Memory": { - "type": "Transitive", - "resolved": "4.5.5", - "contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==" - }, "System.Memory.Data": { "type": "Transitive", "resolved": "6.0.0", - "contentHash": "ntFHArH3I4Lpjf5m4DCXQHJuGwWPNVJPaAvM95Jy/u+2Yzt2ryiyIN04LAogkjP9DeRcEOiviAjQotfmPq/FrQ==", - "dependencies": { - "System.Text.Json": "6.0.0" - } - }, - "System.Numerics.Vectors": { - "type": "Transitive", - "resolved": "4.5.0", - "contentHash": "QQTlPTl06J/iiDbJCiepZ4H//BVraReU4O4EoRw1U02H5TLUIT7xn3GnDp9AXPSlJUDyFs4uWjWafNX6WrAojQ==" - }, - "System.Runtime.CompilerServices.Unsafe": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==" + "contentHash": "ntFHArH3I4Lpjf5m4DCXQHJuGwWPNVJPaAvM95Jy/u+2Yzt2ryiyIN04LAogkjP9DeRcEOiviAjQotfmPq/FrQ==" }, "System.Security.Cryptography.ProtectedData": { "type": "Transitive", "resolved": "4.5.0", "contentHash": "wLBKzFnDCxP12VL9ANydSYhk59fC4cvOr9ypYQLPnAj48NQIhqnjdD2yhP8yEKyBJEjERWS9DisKL7rX5eU25Q==" }, - "System.Text.Encodings.Web": { - "type": "Transitive", - "resolved": "6.0.0", - "contentHash": "Vg8eB5Tawm1IFqj4TVK1czJX89rhFxJo9ELqc/Eiq0eXy13RK00eubyU6TJE6y+GQXjyV5gSfiewDUZjQgSE0w==", - "dependencies": { - "System.Runtime.CompilerServices.Unsafe": "6.0.0" - } - }, - "System.Text.Json": { - "type": "Transitive", - "resolved": "9.0.4", - "contentHash": "pYtmpcO6R3Ef1XilZEHgXP2xBPVORbYEzRP7dl0IAAbN8Dm+kfwio8aCKle97rAWXOExr292MuxWYurIuwN62g==" - }, - "System.Threading.Tasks.Extensions": { - "type": "Transitive", - "resolved": "4.5.4", - "contentHash": "zteT+G8xuGu6mS+mzDzYXbzS7rd3K6Fjb9RiZlYlJPam2/hU7JCBZBVEcywNuR+oZ1ncTvc/cq0faRr3P01OVg==" - }, "YamlDotNet": { "type": "Transitive", "resolved": "16.3.0", @@ -646,10 +382,6 @@ "dependencies": { "Markdig": "[0.41.3, )", "Microsoft.EntityFrameworkCore.Sqlite": "[9.0.4, )", - "Microsoft.Extensions.Configuration": "[9.0.4, )", - "Microsoft.Extensions.Configuration.Binder": "[9.0.4, )", - "Microsoft.Extensions.Configuration.Json": "[9.0.4, )", - "Microsoft.Extensions.Logging.Abstractions": "[9.0.4, )", "Microsoft.OpenApi.Readers": "[1.6.24, )", "Newtonsoft.Json.Schema": "[4.0.1, )", "Scriban": "[6.2.1, )", diff --git a/scripts/local-build.ps1 b/scripts/local-build.ps1 index 97d1754b..d70f7343 100644 --- a/scripts/local-build.ps1 +++ b/scripts/local-build.ps1 @@ -10,7 +10,7 @@ Remove-Item ../bld -Recurse -Force dotnet publish ../DevProxy/DevProxy.csproj -c Release -p:PublishSingleFile=true -r $platform --self-contained -o ../bld -p:InformationalVersion=$version dotnet build ../DevProxy.Plugins/DevProxy.Plugins.csproj -c Release -r $platform --no-self-contained -p:InformationalVersion=$version -cp -R ../DevProxy/bin/Release/net9.0/$platform/plugins ../bld +cp -R ../DevProxy/bin/Release/net10.0/$platform/plugins ../bld pushd cd ../bld From f218d5cbf542596dc4ea231946c02a12f0f00c84 Mon Sep 17 00:00:00 2001 From: waldekmastykarz Date: Sun, 16 Nov 2025 17:08:23 +0100 Subject: [PATCH 2/2] Updates workflows to .NET 10 --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/create-release.yml | 2 +- .github/workflows/dotnet.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index def4021e..f643a063 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -49,7 +49,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index c8c1a60a..fde9a726 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -34,7 +34,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x - name: Rename executable for beta if: contains(github.ref_name, '-beta') run: | diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 745e5cf8..56b80f77 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -22,7 +22,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5.0.0 with: - dotnet-version: 9.0.x + dotnet-version: 10.0.x - name: Restore workloads run: dotnet workload restore - name: Restore dependencies