Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnol-VN committed Jan 22, 2025
1 parent 9c073fc commit 65792c0
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 569 deletions.
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
{
/// <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 @@

using System;

namespace Microsoft.Omex.Extensions.Logging
namespace Microsoft.Omex.Extensions.Abstractions.ServiceContext
{
/// <summary>
/// Interface with service context information
Expand Down
12 changes: 7 additions & 5 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,20 +99,20 @@ private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
.AddOmexServiceFabricDependencies<TContext>()
.AddSingleton<IOmexServiceRegistrator, TRunner>()
.AddHostedService<OmexHostedService>();
collection.TryAddTransient<IServiceContext, EmptyServiceContext>();
collection.TryAddTransient<IExecutionContext, BaseExecutionContext>();
})
.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.CustomizeInitializationLoggerBuilder(loggingBuilder => loggingBuilder.AddConsole());

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

return host;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Hosting.Services/Internal/OmexServiceFabricContext.cs
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
10 changes: 1 addition & 9 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 @@ -18,21 +16,15 @@ public static class ServiceCollectionExtensions
/// <summary>
/// Add Omex Logging and ActivitySource dependencies
/// </summary>
[Obsolete($"Please do not use {nameof(AddOmexServices)} if you just want to use Legacy OmexLogger and ActivityEventSender because they are deprecated. Consider using a different telemetry solution. This method is pending for removal by 1 July 2024. Code: 8913598.")]
public static IHostBuilder AddOmexServices(this IHostBuilder builder) =>
builder
.ConfigureServices((context, collection) => collection.AddOmexServices());

/// <summary>
/// Add Omex Logging and ActivitySource dependencies
/// </summary>
[Obsolete($"Please do not use {nameof(AddOmexServices)} if you just want to use Legacy OmexLogger and ActivityEventSender because they are deprecated. Consider using a different telemetry solution. This method is pending for removal by 1 July 2024. Code: 8913598.")]
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();

/// <summary>
/// Add Omex Logging and ActivitySource dependencies
Expand Down
21 changes: 11 additions & 10 deletions src/Logging/InitializationLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ 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)
{
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;

private static Action<ILoggingBuilder>? s_loggingBuilderAction;

/// <summary>
/// Log on successful building
Expand All @@ -56,7 +57,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

0 comments on commit 65792c0

Please sign in to comment.