Exemplo n.º 1
0
        internal static IDictionary <string, string> GetDestinationConfiguration(LoggerPool loggerPool, string destinationName)
        {
            var configuration = new Dictionary <string, string>();

            var destination = loggerPool
                              .GetDestinations()
                              .FirstOrDefault(d => d.DestinationName == destinationName)?
                              .Destination;

            if (destination == null)
            {
                return(configuration);
            }

            var type       = destination.GetType();
            var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in properties)
            {
                var attribute = property?.GetCustomAttributes(typeof(LogConfigurationNameAttribute), true).FirstOrDefault();

                if (attribute is LogConfigurationNameAttribute nameAttribute)
                {
                    var value = property.GetValue(destination);
                    configuration[nameAttribute.Name] = value?.ToString();
                }
            }

            return(configuration);
        }
Exemplo n.º 2
0
        internal static void SetDestinationConfiguration(LoggerPool loggerPool, string destinationName, IDictionary <string, string> configuration)
        {
            var destination = loggerPool
                              .GetDestinations()
                              .FirstOrDefault(d => d.DestinationName == destinationName)?
                              .Destination;

            if (destination == null)
            {
                return;
            }

            var type       = destination.GetType();
            var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in properties)
            {
                var attribute = property?.GetCustomAttributes(typeof(LogConfigurationNameAttribute), true).FirstOrDefault();

                if (attribute is LogConfigurationNameAttribute nameAttribute &&
                    configuration.TryGetValue(nameAttribute.Name, out var val))
                {
                    if (val == null)
                    {
                        property.SetValue(destination, null);
                    }
                    else
                    {
                        var typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(property.PropertyType);
                        var propVal       = typeConverter.ConvertFromString(val);
                        property.SetValue(destination, propVal);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public LogExecutor(string category, LoggerPool loggerPool)
 {
     _loggerPool = loggerPool;
     _category   = category;
 }
Exemplo n.º 4
0
 private LogAdministrator()
 {
     _loggerPool = new LoggerPool(this);
 }