using System;
using System.Linq;

namespace VCommon.Logging
{
    public sealed class MultiLogger : ILogger
    {
        private readonly ILogger[] _loggers;

        public MultiLogger(params ILogger[] loggers)
        {
            if (loggers.Any(p => p is DefaultLogger)) throw new ArgumentException("Can not use DefaultLogger");
            _loggers = loggers.Where(p => false == p is NullLogger).ToArray();
        }

        public void Debug(string summary, object moreInfo = null)
        {
            foreach (var logger in _loggers) logger.Debug(summary, moreInfo);
        }

        public void Trace(string summary, object moreInfo = null)
        {
            foreach (var logger in _loggers) logger.Trace(summary, moreInfo);
        }

        public void Info(string summary, object moreInfo = null)
        {
            foreach (var logger in _loggers) logger.Info(summary, moreInfo);
        }

        public void Warn(string summary, object moreInfo = null)
        {
            foreach (var logger in _loggers) logger.Warn(summary, moreInfo);
        }

        public void Error(string summary, object moreInfo = null)
        {
            foreach (var logger in _loggers) logger.Error(summary, moreInfo);
        }

        public void Fatal(string summary, object moreInfo = null)
        {
            foreach (var logger in _loggers) logger.Fatal(summary, moreInfo);
        }
    }
}