From cbe8ea201b0bc1a6c177fac4f1ffa223248d211b Mon Sep 17 00:00:00 2001 From: Long Date: Fri, 24 Jan 2025 13:39:04 +0000 Subject: [PATCH] Remove "Microsoft-OMEX-HostLogs" source --- src/Logging/InitializationLogger.cs | 7 -- .../ServiceInitializationEventSource.cs | 89 ------------------- 2 files changed, 96 deletions(-) delete mode 100644 src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs diff --git a/src/Logging/InitializationLogger.cs b/src/Logging/InitializationLogger.cs index abd800a8..6687c96e 100644 --- a/src/Logging/InitializationLogger.cs +++ b/src/Logging/InitializationLogger.cs @@ -46,12 +46,6 @@ public static ILogger Instance public static void LogInitializationSucceed(string serviceNameForLogging, string message = "") { string logMessage = $"Initialization successful for {serviceNameForLogging}, {message}"; -#if NET5_0_OR_GREATER - ServiceInitializationEventSource.Instance.LogHostBuildSucceeded(Environment.ProcessId, serviceNameForLogging, logMessage); -#else - using Process process = Process.GetCurrentProcess(); - ServiceInitializationEventSource.Instance.LogHostBuildSucceeded(process.Id, serviceNameForLogging, logMessage); -#endif Instance.LogInformation(Tag.Create(), logMessage); } @@ -63,7 +57,6 @@ public static void LogInitializationSucceed(string serviceNameForLogging, string /// Message to log public static void LogInitializationFail(string serviceNameForLogging, Exception? ex = null, string message = "") { - ServiceInitializationEventSource.Instance.LogHostFailed(ex?.ToString() ?? string.Empty, serviceNameForLogging, message); Instance.LogError(Tag.Create(), ex, message); } } diff --git a/src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs b/src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs deleted file mode 100644 index db9c1839..00000000 --- a/src/Logging/Internal/EventSource/ServiceInitializationEventSource.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Diagnostics.Tracing; -using Microsoft.Omex.Extensions.Abstractions.EventSources; - -namespace Microsoft.Omex.Extensions.Logging -{ - /// - /// Service Fabric event source - /// - [EventSource(Name = "Microsoft-OMEX-HostLogs")] - internal sealed class ServiceInitializationEventSource : EventSource - { - /// - /// Instance of service fabric event source - /// - public static ServiceInitializationEventSource Instance { get; } = new ServiceInitializationEventSource(); - - /// - /// Logs a generic host build success - /// - /// Host process id - /// Service type - /// Optional message - [NonEvent] - public void LogHostBuildSucceeded(int hostProcessId, string serviceType, string message = "") - { - if (!IsEnabled()) - { - return; - } - - string logMessage = string.IsNullOrWhiteSpace(message) ? - FormattableString.Invariant($"Service host process {hostProcessId} registered service type {serviceType}") : - message; - LogHostBuildSucceededInternal( - hostProcessId, - serviceType, - logMessage); - } - - /// - /// Logs a generic host failure - /// - /// Exception - /// Service type - /// Optional message - [NonEvent] - public void LogHostFailed(string exception, string serviceType, string message = "") - { - if (!IsEnabled()) - { - return; - } - string logMessage = string.IsNullOrWhiteSpace(message) ? - FormattableString.Invariant($"Service host initialization failed for {serviceType} with exception {exception}") : - message; - - LogHostFailedInternal( - exception, - serviceType, - logMessage); - } - - private ServiceInitializationEventSource() { } - - /// - /// Log host build succeeded - /// - /// Host process id - /// The service type - /// The message to be logged - [Event((int)EventSourcesEventIds.GenericHostBuildSucceeded, Level = EventLevel.Informational, Message = "{2}", Version = 1)] - private void LogHostBuildSucceededInternal(int hostProcessId, string serviceType, string message) => - WriteEvent((int)EventSourcesEventIds.GenericHostBuildSucceeded, hostProcessId, serviceType, message); - - /// - /// Log host build failed - /// - /// Exception to be logged - /// The service type - /// The message to be logged - [Event((int)EventSourcesEventIds.GenericHostFailed, Level = EventLevel.Error, Message = "{1}", Version = 1)] - private void LogHostFailedInternal(string exception, string serviceType, string message) => - WriteEvent((int)EventSourcesEventIds.GenericHostFailed, exception, serviceType, message); - } -}