Пример #1
0
        public LogConfig(dynamic config)
        {
            try
            {
                Root = string.IsNullOrEmpty(config.root) ? "logs" : config.root;

                Targets = new List<ILogTarget>();

                if (config.targets is JsonConfig.NullExceptionPreventer)
                    AddDefaults(); // if we don't have any targets defined, setup a few default ones.
                else
                {
                    foreach (var data in config.targets)
                    {
                        var target = new LogTarget(data);
                        if (!target.Valid)
                            continue;

                        Targets.Add(target);
                    }
                }

                Valid = true;
            }
            catch (Exception e)
            {
                Valid = false;
                Log.Logger.ForContext<LogConfig>().Error(e, "Error loading logging configuration");
            }
        }