2017-12-08 14 views
0

だから、私は非常に奇妙な問題があります。 Azure Web Jobがあります。そこにlog4netを追加したいと思っています。WebジョブでLog4net:認識できない設定セクションlog4net - しかし、私は上部にconfigSectionsを持っています

私は次のweb.configファイルを持っています。これは、動作するWebアプリケーションと同じ要素を持っています。 configSectionsの私log4netの宣言がトップでどのように注意してください:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <connectionStrings> 
    <!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" --> 
    <!-- For local execution, the value can be set either in this config file or through environment variables --> 
    <add name="AzureWebJobsDashboard" connectionString="" /> 
    <add name="AzureWebJobsStorage" connectionString="" /> 
    <add name="DefaultConnection" connectionString="" providerName="System.Data.SqlClient" /> 

    </connectionStrings> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> 
    </configSections> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
    <appSettings> 

    <!--Azure Storage--> 
    <add key="StorageConnectionString" value="" /> 
    <add key="DefaultStorageContainer" value="" /> 

    <!-- GatawayApi SMS --> 
    <add key="GatewayApiServiceEnabled" value="FALSE" /> 
    <add key="GatewayApiKey" value="" /> 
    <add key="GatewayApiSecret" value="" /> 

    <!-- Mandrill mail--> 
    <add key="MandrillApiServiceEnabled" value="TRUE" /> 
    <add key="MandrillApiKey" value="" /> 
    </appSettings> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 

    <log4net debug="true"> 
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender"> 
     <bufferSize value="1" /> 
     <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     <connectionStringName value="DefaultConnection" /> 
     <commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" /> 
     <parameter> 
     <parameterName value="@log_date" /> 
     <dbType value="DateTime" /> 
     <layout type="log4net.Layout.RawTimeStampLayout" /> 
     </parameter> 
     <parameter> 
     <parameterName value="@thread" /> 
     <dbType value="String" /> 
     <size value="255" /> 
     <layout type="log4net.Layout.PatternLayout"> 
      <conversionPattern value="%thread" /> 
     </layout> 
     </parameter> 
     <parameter> 
     <parameterName value="@log_level" /> 
     <dbType value="String" /> 
     <size value="50" /> 
     <layout type="log4net.Layout.PatternLayout"> 
      <conversionPattern value="%level" /> 
     </layout> 
     </parameter> 
     <parameter> 
     <parameterName value="@logger" /> 
     <dbType value="String" /> 
     <size value="255" /> 
     <layout type="log4net.Layout.PatternLayout"> 
      <conversionPattern value="%logger" /> 
     </layout> 
     </parameter> 
     <parameter> 
     <parameterName value="@message" /> 
     <dbType value="String" /> 
     <size value="4000" /> 
     <layout type="log4net.Layout.PatternLayout"> 
      <conversionPattern value="%message" /> 
     </layout> 
     </parameter> 
     <parameter> 
     <parameterName value="@exception" /> 
     <dbType value="String" /> 
     <size value="2000" /> 
     <layout type="log4net.Layout.ExceptionLayout" /> 
     </parameter> 
    </appender> 
    <root> 
     <level value="DEBUG"/> 
     <appender-ref ref="AdoNetAppender" /> 
    </root> 
    </log4net> 
</configuration> 

しかし、私はダッシュボード内のAzureのWebジョブのログを開くとき:

Unhandled Exception: System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section log4net. (D:\local\Temp\jobs\continuous\CommunicationSender\13a4pcai.5fk\CommunicationSender.exe.config line 70) 

誰もが何が起こっている任意の手掛かりを持っていますここに? :-)私は何が欠けていますか?

は、私はこのようなコードでlog4netのを初期化しますが、私はこれが原因構成の問題のヒットされることはありませんと仮定します。

static void Main() 
     { 
      log4net.Config.XmlConfigurator.Configure(); 
      ILog log = log4net.LogManager.GetLogger(typeof(Program)); 
      log.Info("CommunicationSender STARTED! :-)"); 

      var config = new JobHostConfiguration(); 

      if (config.IsDevelopment) 
      { 
       config.UseDevelopmentSettings(); 
      } 

      var host = new JobHost(); 
      // The following code ensures that the WebJob will be running continuously 
      host.RunAndBlock(); 
     } 
+0

おそらくこのファイルはインスタンスで更新されていませんか?もう1つの方法は、xmlを直接ロードすることです。http://logging.apache.org/log4net/release/manual/configuration.html – Artyom

+0

@Artyom Hmm私は削除し、アプリを数回作成しました。かなり私の設定にいくつかのバグがありますが、私は正直少しばかげているよ!リンクを詳細に読んでください。 –

+0

Kudu Consoleから手動で実行してみてください。同じエラーが発生した場合、WebJobとは何の関係もないことがわかります。 –

答えて

0

問題は私の従業員のいずれかによって解決しました。彼は、configSectionはConnectionStringsの前にある必要があることを指摘しました。

周囲の人を切り替えた後、うまくいった!

関連する問題