Ejemplo n.º 1
0
    public void Invalid_Definitition_Throws_InvalidServiceDefinitionException(string definition)
    {
        // Arrange

        // Act
        var action = void() => ServicesConfig.SplitDefinition(definition);

        // Assert
        var ex = Assert.Throws <InvalidServiceDefinitionException>(action);

        Assert.Equal(string.Format(InvalidServiceDefinitionException.Format, definition), ex.Message);
    }
Ejemplo n.º 2
0
    public void Returns_Split_Definition()
    {
        // Arrange
        var type = Rnd.Str;
        var name = Rnd.Str;
        var d0   = $"{type}.{name}";
        var d1   = $"{type}";

        // Act
        var(t0, n0) = ServicesConfig.SplitDefinition(d0);
        var(t1, n1) = ServicesConfig.SplitDefinition(d1);

        // Assert
        Assert.Equal(type, t0);
        Assert.Equal(name, n0);
        Assert.Equal(type, t1);
        Assert.Equal(string.Empty, n1);
    }
    /// <summary>
    /// Configure all enabled <see cref="ILoggingProvider"/> services
    /// </summary>
    /// <param name="serilog"></param>
    /// <param name="jeebs"></param>
    internal static void ConfigureProviders(ref LoggerConfiguration serilog, JeebsConfig jeebs)
    {
        // Get enabled providers
        var enabledProviders = jeebs.Logging.Providers.Where(h => h.Value.Enabled).ToList();

        // If no providers are enabled, add basic console logging and return
        if (enabledProviders.Count == 0)
        {
            _ = serilog.WriteTo.Console();
            return;
        }

        // Get provider services
        var providers = new Dictionary <string, ILoggingProvider>();

        TypeF.GetTypesImplementing <ILoggingProvider>().ForEach(t =>
        {
            var i = Activator.CreateInstance(t);
            if (i is ILoggingProvider h)
            {
                providers.Add(h.Type, h);
            }
        });

        // Configure enabled providers
        foreach (var(providerInfo, providerConfig) in enabledProviders)
        {
            // Get service definition
            var(serviceType, serviceName) = ServicesConfig.SplitDefinition(providerInfo);

            // Get hook minimum - default minimum will override this if it's higher
            var providerMinimum = GetMinimum(providerConfig.Minimum, jeebs.Logging.Minimum);

            // Configure provider
            if (providers.TryGetValue(serviceType, out var provider))
            {
                provider.Configure(serilog, jeebs, serviceName, providerMinimum);
            }
        }
    }