我们正在尝试将一些动态可配置的日志记录实现到我们的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>
Run Code Online (Sandbox Code Playgroud)
解决了(请原谅这个窗口中的格式):
<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>
Run Code Online (Sandbox Code Playgroud)
我看不到愚弄ServiceDefinition或ServiceConfiguration文件来接受这个的方法,尽管我可以看到一种方法告诉企业库使用我可以在app.config中执行的ServiceConfiguration文件.
为什么我们试图解决这个问题是为了允许我们动态调整日志记录的设置,即从No logging更改为Verbose而不必进行重新部署,这在我们的实时应用程序中证明是耗时且不切实际的住,所以可能还有奇怪的虫子;-) …
我正在查看一些代码(我没有写它!)来测试我们的代码在尝试删除存在依赖项的表行时捕获了两个错误条件.
代码最初在消息中查找特定文本而不是使用错误号.
为了提供多语言支持,最好根据错误号而不是错误消息捕获异常.
在测试中,代码正在寻找两组文本,我似乎无法确定区别是什么,所以只是检查错误号547是不舒服的.
假设两个错误消息的错误号都是547是否安全?干杯科林