From 2e116c5c3a931ec352b749af10a8aaa3be917379 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 4 Apr 2024 15:43:06 +0100 Subject: [PATCH] Formatting --- sample/WorkerServiceSample/Worker.cs | 6 ++++-- .../ServiceCollectionExtensions.cs | 2 +- .../Elastic.Apm.Extensions.Hosting/ApmService.cs | 6 ++++-- .../Elastic.Apm.Extensions.Hosting/NetCoreLogger.cs | 6 ++++-- .../ServiceCollectionExtensions.cs | 12 ++++++------ .../ApmErrorLoggingProvider.cs | 6 ++++-- .../ServiceCollectionExtensions.cs | 2 +- .../Elastic.Apm.Tests.Utilities/MockPayloadSender.cs | 2 +- .../HostingTests.cs | 8 ++++---- .../ExtensionsTestHelpers.cs | 6 ++++-- .../applications/HostingTestApp/Program.cs | 12 ++++++------ 11 files changed, 39 insertions(+), 29 deletions(-) diff --git a/sample/WorkerServiceSample/Worker.cs b/sample/WorkerServiceSample/Worker.cs index 35d8ed9db6..c5c0253580 100644 --- a/sample/WorkerServiceSample/Worker.cs +++ b/sample/WorkerServiceSample/Worker.cs @@ -2,11 +2,13 @@ namespace WorkerServiceSample { - public class Worker(IHttpClientFactory httpClientFactory) : BackgroundService + public class Worker : BackgroundService { - private readonly IHttpClientFactory _httpClientFactory = httpClientFactory; + private readonly IHttpClientFactory _httpClientFactory; private static readonly ActivitySource ActivitySource = new("MyActivitySource"); + public Worker(IHttpClientFactory httpClientFactory) => _httpClientFactory = httpClientFactory; + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) diff --git a/src/integrations/Elastic.Apm.AspNetCore/ServiceCollectionExtensions.cs b/src/integrations/Elastic.Apm.AspNetCore/ServiceCollectionExtensions.cs index d8d010e436..dbc4734c8b 100644 --- a/src/integrations/Elastic.Apm.AspNetCore/ServiceCollectionExtensions.cs +++ b/src/integrations/Elastic.Apm.AspNetCore/ServiceCollectionExtensions.cs @@ -30,7 +30,7 @@ public static IServiceCollection AddElasticApmForAspNetCore(this IServiceCollect { var subs = subscribers.ToList(); subs.Add(new AspNetCoreDiagnosticSubscriber()); - services.AddElasticApm([.. subs]); + services.AddElasticApm([..subs]); } return services; diff --git a/src/integrations/Elastic.Apm.Extensions.Hosting/ApmService.cs b/src/integrations/Elastic.Apm.Extensions.Hosting/ApmService.cs index 6c9db17f2d..b4f57b0259 100644 --- a/src/integrations/Elastic.Apm.Extensions.Hosting/ApmService.cs +++ b/src/integrations/Elastic.Apm.Extensions.Hosting/ApmService.cs @@ -12,12 +12,14 @@ namespace Elastic.Apm.NetCoreAll; /// When registered into the DI container, this ensures that an instance of is /// created by invoking the implementation factory. /// -internal sealed class ApmService(IApmAgent agent) : IHostedService +internal sealed class ApmService : IHostedService { #pragma warning disable IDE0052 // Remove unread private members - private readonly IApmAgent _agent = agent; + private readonly IApmAgent _agent; #pragma warning restore IDE0052 // Remove unread private members + public ApmService(IApmAgent agent) => _agent = agent; + public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask; public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; } diff --git a/src/integrations/Elastic.Apm.Extensions.Hosting/NetCoreLogger.cs b/src/integrations/Elastic.Apm.Extensions.Hosting/NetCoreLogger.cs index a57918ad30..f806f34994 100644 --- a/src/integrations/Elastic.Apm.Extensions.Hosting/NetCoreLogger.cs +++ b/src/integrations/Elastic.Apm.Extensions.Hosting/NetCoreLogger.cs @@ -9,9 +9,11 @@ namespace Elastic.Apm.Extensions.Hosting; -internal sealed class NetCoreLogger(ILoggerFactory loggerFactory) : IApmLogger +internal sealed class NetCoreLogger : IApmLogger { - private readonly ILogger _logger = loggerFactory?.CreateLogger("Elastic.Apm") ?? throw new ArgumentNullException(nameof(loggerFactory)); + private readonly ILogger _logger; + + public NetCoreLogger(ILoggerFactory loggerFactory) => _logger = loggerFactory?.CreateLogger("Elastic.Apm") ?? throw new ArgumentNullException(nameof(loggerFactory)); public bool IsEnabled(LogLevel level) => _logger.IsEnabled(Convert(level)); diff --git a/src/integrations/Elastic.Apm.Extensions.Hosting/ServiceCollectionExtensions.cs b/src/integrations/Elastic.Apm.Extensions.Hosting/ServiceCollectionExtensions.cs index 89fda76cfc..1923e42e21 100644 --- a/src/integrations/Elastic.Apm.Extensions.Hosting/ServiceCollectionExtensions.cs +++ b/src/integrations/Elastic.Apm.Extensions.Hosting/ServiceCollectionExtensions.cs @@ -2,20 +2,20 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information -using Elastic.Apm; using System; -using Elastic.Apm.Extensions.Hosting; +using Elastic.Apm; using Elastic.Apm.Config; +using Elastic.Apm.DiagnosticSource; +using Elastic.Apm.Extensions.Hosting; using Elastic.Apm.Extensions.Hosting.Config; -using Microsoft.Extensions.Hosting; +using Elastic.Apm.Extensions.Logging; using Elastic.Apm.Logging; -using Elastic.Apm.DiagnosticSource; using Elastic.Apm.NetCoreAll; using Elastic.Apm.Report; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Elastic.Apm.Extensions.Logging; using static Microsoft.Extensions.DependencyInjection.ServiceDescriptor; -using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/integrations/Elastic.Apm.Extensions.Logging/ApmErrorLoggingProvider.cs b/src/integrations/Elastic.Apm.Extensions.Logging/ApmErrorLoggingProvider.cs index b9ccceacac..fb43a2770f 100644 --- a/src/integrations/Elastic.Apm.Extensions.Logging/ApmErrorLoggingProvider.cs +++ b/src/integrations/Elastic.Apm.Extensions.Logging/ApmErrorLoggingProvider.cs @@ -6,9 +6,11 @@ namespace Elastic.Apm.Extensions.Logging { - internal class ApmErrorLoggingProvider(IApmAgent apmAgent) : ILoggerProvider + internal class ApmErrorLoggingProvider : ILoggerProvider { - private readonly IApmAgent _apmAgent = apmAgent; + private readonly IApmAgent _apmAgent; + + public ApmErrorLoggingProvider(IApmAgent apmAgent) => _apmAgent = apmAgent; public ILogger CreateLogger(string categoryName) => new ApmErrorLogger(_apmAgent); diff --git a/src/integrations/Elastic.Apm.NetCoreAll/ServiceCollectionExtensions.cs b/src/integrations/Elastic.Apm.NetCoreAll/ServiceCollectionExtensions.cs index 7e6f92db4c..018e591aee 100644 --- a/src/integrations/Elastic.Apm.NetCoreAll/ServiceCollectionExtensions.cs +++ b/src/integrations/Elastic.Apm.NetCoreAll/ServiceCollectionExtensions.cs @@ -2,11 +2,11 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information -using Elastic.Apm.DiagnosticSource; using Elastic.Apm.AspNetCore.DiagnosticListener; using Elastic.Apm.Azure.CosmosDb; using Elastic.Apm.Azure.ServiceBus; using Elastic.Apm.Azure.Storage; +using Elastic.Apm.DiagnosticSource; using Elastic.Apm.Elasticsearch; using Elastic.Apm.EntityFrameworkCore; using Elastic.Apm.GrpcClient; diff --git a/test/Elastic.Apm.Tests.Utilities/MockPayloadSender.cs b/test/Elastic.Apm.Tests.Utilities/MockPayloadSender.cs index 36ccf1f028..c72b7c21dd 100644 --- a/test/Elastic.Apm.Tests.Utilities/MockPayloadSender.cs +++ b/test/Elastic.Apm.Tests.Utilities/MockPayloadSender.cs @@ -20,7 +20,7 @@ namespace Elastic.Apm.Tests.Utilities { internal class MockPayloadSender : IPayloadSender - { + { private static readonly JObject JsonSpanTypesData = JObject.Parse(File.ReadAllText(Path.Combine(SolutionPaths.Root, "test/Elastic.Apm.Tests.Utilities/TestResources/json-specs/span_types.json"))); diff --git a/test/integrations/Elastic.Apm.Extensions.Hosting.Tests/HostingTests.cs b/test/integrations/Elastic.Apm.Extensions.Hosting.Tests/HostingTests.cs index 44ae0ed798..f1b1f39536 100644 --- a/test/integrations/Elastic.Apm.Extensions.Hosting.Tests/HostingTests.cs +++ b/test/integrations/Elastic.Apm.Extensions.Hosting.Tests/HostingTests.cs @@ -12,16 +12,16 @@ namespace Elastic.Apm.Extensions.Hosting.Tests { public class HostingTests - { - private readonly ExtensionsTestHelper _extensionsTestHelper; + { + private readonly ExtensionsTestHelper _extensionsTestHelper; public HostingTests(ITestOutputHelper output) - { + { _extensionsTestHelper = new(output); _extensionsTestHelper.TestSetup(); } - [Fact] + [Fact] public async Task AddElasticApm_WhenEnabledIsNotConfigured() => await _extensionsTestHelper.ExecuteTestProcessAsync(null, false, false, false, false); diff --git a/test/integrations/Elastic.Apm.Extensions.Tests.Shared/ExtensionsTestHelpers.cs b/test/integrations/Elastic.Apm.Extensions.Tests.Shared/ExtensionsTestHelpers.cs index f15ac4f23a..e8c8459c8a 100644 --- a/test/integrations/Elastic.Apm.Extensions.Tests.Shared/ExtensionsTestHelpers.cs +++ b/test/integrations/Elastic.Apm.Extensions.Tests.Shared/ExtensionsTestHelpers.cs @@ -9,10 +9,12 @@ namespace Elastic.Apm.Extensions.Tests.Shared; -public class ExtensionsTestHelper(ITestOutputHelper testOutput) +public class ExtensionsTestHelper { private readonly string _workingDirectory = Path.Combine(SolutionPaths.Root, "test", "integrations", "applications", "HostingTestApp"); - private readonly ITestOutputHelper _testOutput = testOutput; + private readonly ITestOutputHelper _testOutput; + + public ExtensionsTestHelper(ITestOutputHelper testOutput) => _testOutput = testOutput; public void TestSetup() { diff --git a/test/integrations/applications/HostingTestApp/Program.cs b/test/integrations/applications/HostingTestApp/Program.cs index b671e58f27..9ab73521ca 100644 --- a/test/integrations/applications/HostingTestApp/Program.cs +++ b/test/integrations/applications/HostingTestApp/Program.cs @@ -3,13 +3,13 @@ // See the LICENSE file in the project root for more information using Elastic.Apm; +using Elastic.Apm.Api; using Elastic.Apm.DiagnosticSource; -using Test; using Elastic.Apm.Extensions.Hosting; -using Elastic.Apm.Api; -using SampleConsoleNetCoreApp; -using Elastic.Apm.Tests.Utilities; using Elastic.Apm.Report; +using Elastic.Apm.Tests.Utilities; +using SampleConsoleNetCoreApp; +using Test; // This is an application used to test the Elastic.Apm.Extensions.Hosting and Elastic.Apm.Extensions.Logging // packages. It is used by the Elastic.Apm.Extensions.Hosting.Tests project which starts this application @@ -35,7 +35,7 @@ { enabled = null; } -else +else { if (!bool.TryParse(args[0], out var e)) throw new Exception("The first argument must be true, false or unset."); @@ -190,7 +190,7 @@ if (payloadSender.Errors.SingleOrDefault(n => n.Log.Message == errorLogWithException && n.Log.StackTrace != null && n.Log.StackTrace.Count > 0) is null) - throw new Exception($"Expected one error log with exception."); + throw new Exception($"Expected one error log with exception."); } // Perform assertions based on the configuration