我们正在尝试将一些动态可配置的日志记录实现到我们的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}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
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存储或数据库中保留额外的配置(使管理部署的生活更简单)