private void LoadWritersType() { if (_config.Writers == null || _config.Writers.Length == 0) { throw new LogConfigException("日志配置文件中,没有配置Writers节点。"); } foreach (var w in _config.Writers) { if (string.IsNullOrEmpty(w.Name)) { throw new LogConfigException("日志配置文件中,写入器的 Name 属性不能为空。"); } if (string.IsNullOrEmpty(w.Type)) { throw new LogConfigException("日志配置文件中,写入器的 Type 属性不能为空。"); } // 如果指定的类型不正确,下面代码会抛出异常 Type t = Type.GetType(w.Type, true); if (typeof(ILogWriter).IsAssignableFrom(t) == false) { throw new LogConfigException("日志配置文件中,指定的WriteType没有实现接口ILogWriter:" + w.Type); } ILogWriter instance = Activator.CreateInstance(t) as ILogWriter; instance.Init(w); _writerNameTypeDict[w.Name] = w.Type; } // 增加一个内置的,可用于开发环境中不写日志 _writerNameTypeDict["NULL"] = "ClownFish.Log.Serializer.NullWriter, ClownFish.Log"; }