微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.net – ServiceConfiguration.cscfg中的自定义/嵌套XML设置

我们正在尝试将一些动态可配置的日志记录实现到我们的Azure应用程序中,并且我们正在使用企业库来完成这项工作,但是为了实现这一点而需要的xml比ServiceConfiguration的简单“appSetting”样式设置更复杂. .cscfg文件似乎接受,因为它需要嵌套的xml节点,

例如

<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,Microsoft.Practices.EnterpriseLibrary.Logging,Version=5.0.414.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>

解决了(请原谅这个窗口中的格式):

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
        <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData,PublicKeyToken=31bf3856ad364e35"
            type="OurSolution.Common.AzureDiagnosticTraceListener,Common,Version=1.0.0.0,PublicKeyToken=null"
            name="AzureDiagnosticTraceListener" />
    </listeners>
    <formatters>
        <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.textformatter,PublicKeyToken=31bf3856ad364e35"
            template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
            name="Text Formatter" />
    </formatters>
    <categorySources>
        <add switchValue="All" name="General">
            <listeners>
                <add name="AzureDiagnosticTraceListener" />
            </listeners>
        </add>
    </categorySources>
</loggingConfiguration>

我看不到愚弄ServiceDeFinition或ServiceConfiguration文件来接受这个的方法,尽管我可以看到一种方法告诉企业库使用我可以在app.config中执行的ServiceConfiguration文件.

为什么我们试图解决这个问题是为了允许我们动态调整日志记录的设置,即从No logging更改为Verbose而不必进行重新部署,这在我们的实时应用程序中证明是耗时且不切实际的住,所以可能还有奇怪的虫子;-)

任何想法都会非常感激
问候
Kindo Malay

其他选择:

>任意配置的Base64编码,并将它们放入cscfg的值>(我最喜欢的)只需在blob存储或数据库中保留额外的配置(使管理部署的生活更简单)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。