azure - 使用 Enterprise Library 5 登录到 SQL Azure 可以从开发计算机工作,但不能从 Web 角色工作

标签 azure enterprise-library azure-sql-database azure-web-roles

我使用 SQL Azure 作为使用企业库 5 的日志存储库。 我正在使用 azure 的所有部署连接字符串和数据库连接字符串从自己的计算机运行完整的集成测试,并尝试将日志写入数据库。 这很好用!

但是当实际部署在登台环境中并尝试写入日志时,没有抛出异常,但也没有写入日志。

这是我的 app.config 相关部分:

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <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" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" />
  </configSections>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="MainLogger"
      revertImpersonation="false">
    <listeners>
      <add name="LoggingDb" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          databaseInstanceName="LoggingDb" writeLogStoredProcName="WriteLog"
          addCategoryStoredProcName="AddCategory" traceOutputOptions="DateTime, Timestamp, ProcessId, ThreadId, Callstack" />
    </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}&#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="MainLogger">
        <listeners>
          <add name="LoggingDb" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="LoggingDb" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="LoggingDb" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="LoggingDb" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <dataConfiguration defaultDatabase="LoggingDb" />
  <connectionStrings>
    <add name="LoggingDb" connectionString="Server=tcp:********.database.windows.net,1433;Database=****.Logging;User ID=*******@*******;Password=**********;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

我收到以下异常:

配置“listenerDataType=”Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData、Microsoft.Practices.EnterpriseLibrary.Logging.Database、Version=5.0.414.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35”中的无效 TraceListenerData 类型'。 (E:\sitesroot\0\web.config 第 30 行)

在开发中它可以工作...... 对此有什么想法或经验吗?

问候,

詹姆斯

最佳答案

是的,正如所评论的,以下是必须位于您的服务目录中的 dll,以便日志记录 block 能够运行:

Microsoft.Practices.Unity.dll
Microsoft.Practices.ServiceLocation.dll
Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll

关于azure - 使用 Enterprise Library 5 登录到 SQL Azure 可以从开发计算机工作,但不能从 Web 角色工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9781405/

相关文章:

javascript - 在Node中,如何从全局数据库连接执行sql

asp.net - 将 ASP.NET Core Razor 页面部署到 Azure 应用服务

azure - Azure WorkerRole 可以检测到它所在的位置吗?

带有继续 token 的 Azure 逻辑应用配置

c# - 为什么在调用 ExceptionPolicy.HandleException 时会出现 System.InvalidOperationException?

log4net 与 MS 日志记录应用程序 block

c# - 记录应用程序 block

Azure SQL 数据库 - Active Directory 集成身份验证

azure - Azure AD 资源组的体系结构

azure - 与旧库相比,新库的 Cosmos DB 速度非常慢