我将Enterprise Library配置XML序列化并加载到String对象中。
有没有办法用该字符串初始化Enterprise Library日志记录组件?
我正在寻找类似的东西:
IConfigurationSource configSource = new SomethingConfigurationSource(stringWhichHasConfig);
LogWriterFactory logFactory = new LogWriterFactory(configSource);
LogWriter writer = logFactory.Create();
有没有办法真正做到这一点?
答案 0 :(得分:0)
将字符串反序列化为ent lib理解的配置对象。
答案 1 :(得分:0)
我的解决方法是将配置写入临时文件,并按如下方式加载该配置:
string loggingConfigSetting = GetSetting("LoggingConfiguration");
string tempConfigPath = Path.GetTempFileName();
File.AppendAllText(tempConfigPath, loggingConfigSetting);
FileConfigurationSource configSource = new FileConfigurationSource(tempConfigPath);
LogWriterFactory logFactory = new LogWriterFactory(configSource);
writer = logFactory.Create();