Orientation of various suppliers to the registrar

Can’t I target different logging providers based on which registrar I’m using?

For example, refer to the code below:

// Establish loggers
var someLogger = loggerFactory.CreateLogger("SomeLogger");
var anotherLogger = loggerFactory.CreateLogger("AnotherLogger");

// Hook up providers (but not at the individual logger level??)
loggerFactory.AddDebug(minimumLevel: LogLevel.Debug);
loggerFactory.AddConsole(minimumLevel: LogLevel.Debug);
loggerFactory.AddBlob(connectionString, minimumLevel: LogLevel.Information);

// Log stuff
someLogger.LogError("Logging with someLogger");
anotherLogger.LogError("Logging with anotherLogger");

All providers will register here, regardless of which registrar is used.

Is it really impossible? What is the point of identifying individual registrars if they are all registered independently of the provider?

+4
source share
1 answer

, , , , - . API SourceSwitch. , , , .

private static void ConfigureLogging(ILoggerFactory loggerFactory)
{
    var sourceSwitch = new SourceSwitch("EventLog");
    sourceSwitch.Level = SourceLevels.Warning;
    loggerFactory.AddTraceSource(sourceSwitch, new EventLogTraceListener("Application"));
}

UPDATE

ASP.NET 5 , AddProvider ILoggerFactory , :

/// <summary>
/// Used to create logger instances of the given name.
/// </summary>
public interface ILoggerFactory : IDisposable
{
    /// <summary>
    /// The minimum level of log messages sent to registered loggers.
    /// </summary>
    LogLevel MinimumLevel { get; set; }

    /// <summary>
    /// Creates a new ILogger instance of the given name.
    /// </summary>
    /// <param name="categoryName"></param>
    /// <returns></returns>
    ILogger CreateLogger(string categoryName);

    void AddProvider(ILoggerProvider provider);
}

, ILoggerFactory, . ILoggerFactory , .

0

Source: https://habr.com/ru/post/1611718/


All Articles