Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove omexlogger #713

Merged
merged 16 commits into from
Jan 29, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@

using System;

namespace Microsoft.Omex.Extensions.Logging
namespace Microsoft.Omex.Extensions.Abstractions.ServiceContext
{
/// <summary>
/// IServiceContext without any information
/// </summary>
internal class EmptyServiceContext : IServiceContext
public class EmptyServiceContext : IServiceContext
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Service fabric PartitionId
/// </summary>
public Guid PartitionId => Guid.Empty;

/// <summary>
/// Service fabric
/// </summary>
public long ReplicaOrInstanceId => 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
using System;

namespace Microsoft.Omex.Extensions.Logging
namespace Microsoft.Omex.Extensions.Abstractions.ServiceContext
{
/// <summary>
/// Interface with service context information
Expand Down
13 changes: 5 additions & 8 deletions src/Hosting.Services/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Omex.Extensions.Abstractions;
using Microsoft.Omex.Extensions.Abstractions.Accessors;
using Microsoft.Omex.Extensions.Abstractions.ExecutionContext;
using Microsoft.Omex.Extensions.Abstractions.ServiceContext;
using Microsoft.Omex.Extensions.Logging;
using Microsoft.ServiceFabric.Data;

Expand Down Expand Up @@ -97,29 +99,24 @@ private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
.AddOmexServiceFabricDependencies<TContext>()
.AddSingleton<IOmexServiceRegistrator, TRunner>()
.AddHostedService<OmexHostedService>();
collection.TryAddTransient<IServiceContext, EmptyServiceContext>();
collection.TryAddTransient<IExecutionContext, BaseExecutionContext>();
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
})
.UseDefaultServiceProvider(options =>
{
options.ValidateOnBuild = true;
options.ValidateScopes = true;
})
#pragma warning disable OMEX188 // AddOmexLogging using OmexLogger is obsolete. DiagnosticId = "OMEX188"
.ConfigureLogging(builder => builder.AddOmexLogging())
#pragma warning restore OMEX188 // AddOmexLogging using OmexLogger is obsolete. DiagnosticId = "OMEX188"
.ConfigureLogging(builder => builder.AddConfiguration())
.Build();

#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"
InitializationLogger.LogInitializationSucceed(serviceNameForLogging);
#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"

return host;
}
catch (Exception e)
{
#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"
InitializationLogger.LogInitializationFail(serviceNameForLogging, e);
#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"

throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Fabric;
using Microsoft.Omex.Extensions.Abstractions;
using Microsoft.Omex.Extensions.Logging;
using Microsoft.Omex.Extensions.Abstractions.ServiceContext;

namespace Microsoft.Omex.Extensions.Hosting.Services
{
Expand Down
2 changes: 0 additions & 2 deletions src/Hosting/Certificates/InitializationCertificateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public static class InitializationCertificateReader
/// <summary>
/// Instance of CertificateReader
/// </summary>
#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024.
public static ICertificateReader Instance { get; } = new CertificateReader(new CertificateStore(), InitializationLogger.Instance);
#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024.
}
}
8 changes: 1 addition & 7 deletions src/Hosting/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Omex.Extensions.Hosting.Certificates;
using Microsoft.Omex.Extensions.Logging;

namespace Microsoft.Omex.Extensions.Hosting
{
Expand All @@ -26,11 +24,7 @@ public static IHostBuilder AddOmexServices(this IHostBuilder builder) =>
/// Add Omex Logging and ActivitySource dependencies
/// </summary>
public static IServiceCollection AddOmexServices(this IServiceCollection collection) =>
#pragma warning disable OMEX188 // OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger.
collection
.AddOmexLogging()
#pragma warning restore OMEX188 // OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger.
.AddOmexActivitySource();
collection.AddOmexActivitySource();
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Add Omex Logging and ActivitySource dependencies
Expand Down
33 changes: 19 additions & 14 deletions src/Logging/InitializationLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@ namespace Microsoft.Omex.Extensions.Logging
/// InitializationLogger is the logger to be used before the proper ILogger from DI is set.
/// Not to be used as main logger.
/// </summary>
[Obsolete($"{nameof(InitializationLogger)} using {nameof(OmexLogger)} is obsolete and is pending for removal by 1 July 2024.", DiagnosticId = "OMEX188")]
public static class InitializationLogger
{
/// <summary>
/// Instance of logger
/// </summary>
public static ILogger Instance { get; private set; } = LoggerFactory.Create(builder =>
{
builder.LoadInitializationLogger();
}).CreateLogger("Initial-Logging");

private static ILoggingBuilder LoadInitializationLogger(this ILoggingBuilder builder)
public static ILogger Instance
{
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
builder.AddConsole();
}
get =>
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved
LoggerFactory.Create(builder =>
{
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
builder.AddConsole();
}

builder.AddOmexLogging();
return builder;
s_loggingBuilderAction?.Invoke(builder);
}).CreateLogger("Initial-Logging");
}

/// <summary>
/// Action to customize the initialization logger builder
/// </summary>
/// <param name="action"></param>
public static void CustomizeInitializationLoggerBuilder(Action<ILoggingBuilder> action) => s_loggingBuilderAction = action;
Gnol-VN marked this conversation as resolved.
Show resolved Hide resolved

private static Action<ILoggingBuilder>? s_loggingBuilderAction;

/// <summary>
/// Log on successful building
/// </summary>
Expand All @@ -56,7 +61,7 @@ public static void LogInitializationSucceed(string serviceNameForLogging, string
/// <param name="serviceNameForLogging">Service name for logging</param>
/// <param name="ex">Exception to log</param>
/// <param name="message">Message to log</param>
public static void LogInitializationFail(string serviceNameForLogging, Exception? ex = null, string message = "")
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);
Expand Down
126 changes: 0 additions & 126 deletions src/Logging/Internal/EventSource/OmexLogEventSender.cs

This file was deleted.

Loading
Loading