【发布时间】:2011-05-04 06:12:44
【问题描述】:
我们正在尝试在我们的 Azure 应用程序中实现一些可动态配置的日志记录,并且我们正在使用企业库来执行此操作,效果很好,但是实现这一点所需的 xml 比简单的“appSetting”样式设置更复杂ServiceConfiguration.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, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
type="OurSolution.Common.AzureDiagnosticTraceListener, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
name="AzureDiagnosticTraceListener" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, 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 文件。
为什么我们试图解决这个问题是为了允许我们动态调整日志记录的设置,即从无日志记录更改为详细而无需重新部署,这在我们的实时应用程序中证明是耗时且不切实际的只是最近才上线,所以可能仍然存在奇怪的错误;-)
任何想法都将不胜感激 问候 Kindo马来语
【问题讨论】:
标签: .net logging azure enterprise-library