36 lines
1.8 KiB
C#
36 lines
1.8 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
|
|
// This file is part of the EonaCat project(s) which is released under the Apache License.
|
|
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
|
|
|
|
namespace EonaCat.Logger.EonaCatCoreLogger.Extensions
|
|
{
|
|
/// <summary>
|
|
/// Provides extension methods for registering the EonaCat UDP logger with an <see cref="ILoggingBuilder"/>.
|
|
/// </summary>
|
|
/// <remarks>These extension methods enable integration of the EonaCat UDP logger into the logging
|
|
/// pipeline using dependency injection. Use these methods to configure and add UDP-based logging to your
|
|
/// application's logging providers.</remarks>
|
|
public static class UdpLoggerFactoryExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds a UDP-based logger to the logging builder using the specified configuration options.
|
|
/// </summary>
|
|
/// <remarks>Call this method to enable logging over UDP in your application. The provided
|
|
/// configuration action allows customization of UDP logger settings such as endpoint and formatting.</remarks>
|
|
/// <param name="builder">The logging builder to which the UDP logger will be added.</param>
|
|
/// <param name="configure">An action to configure the <see cref="UdpLoggerOptions"/> for the UDP logger. Cannot be null.</param>
|
|
/// <returns>The <see cref="ILoggingBuilder"/> instance for chaining.</returns>
|
|
public static ILoggingBuilder AddEonaCatUdpLogger(this ILoggingBuilder builder, Action<UdpLoggerOptions> configure)
|
|
{
|
|
var options = new UdpLoggerOptions();
|
|
configure?.Invoke(options);
|
|
|
|
builder.Services.AddSingleton<ILoggerProvider>(new UdpLoggerProvider(options));
|
|
return builder;
|
|
}
|
|
}
|
|
}
|