azure - 如何动态/以编程方式设置 Enterprise Library 数据库跟踪监听器连接字符串

标签 azure enterprise-library tracelistener trace-listener

有没有办法动态/以编程方式设置 EntLib 5 数据库跟踪监听器使用的连接字符串?

我在 Windows Azure 中托管我的 WCF 服务,这意味着部署后我将无法访问 web.config。为了消除每当我想将数据库跟踪监听器指向不同数据库时重新部署解决方案的需要,我希望有一种方法可以从我的服务配置文件中提取该设置并动态设置它。

最佳答案

是的,您可以使用the fluent configuration如上所述in this post :

var builder = new ConfigurationSourceBuilder();
builder.ConfigureData()
        .ForDatabaseNamed("MyDb")
        .ThatIs.ASqlDatabase()
        .WithConnectionString(RoleEnvironment.GetConfigurationSettingValue("MyConnectionString"))
        .AsDefault();

builder.ConfigureLogging()
        .WithOptions
        .LogToCategoryNamed("General")
        .SendTo
        .Database("Formatted Database TraceListener").UseDatabase("MyDb")
        ...;

var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

关于azure - 如何动态/以编程方式设置 Enterprise Library 数据库跟踪监听器连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12355288/

相关文章:

c# - Azure web.app AI : Performance counter is not available in the web app supported list

c# - 尝试在 blobstorage 触发函数中引用 CloudBlockBlob 时出现编译错误

enterprise-library - 哪里可以得到政策注入(inject)的简单解释?

.net - 如何为日志应用程序 block 提供自定义连接字符串而不是使用 .config 文件中的连接字符串?

system.diagnostics - 我收到 ConfigurationErrorsException "Couldn' t find constructor for class CustomListener”

c# - 我可以使用 TraceListener 在初始化数据中添加时间戳吗?

asp.net - 如何从控制台运行 Azure 部署 PowerShell 脚本

class - Enterprise Library 5.0 不显示命名空间 Microsoft.Practices.EnterpriseLibrary.Data

c# - 关闭/重新打开使用 XML 配置创建的 TraceListener,指向外部 USB 内存棒

c# - Fabric 消息太大