2016-12-21 66 views
-1

我想使用Elmah來記錄我的web api應用程序的錯誤日誌。我喜歡它將錯誤記錄到web項目中的我的App_Data文件夾。但目前這不起作用。我最初安裝了elmah。並可以通過訪問我的本地主機:PORT/elmah.axd來查看錯誤日誌。但是沒有任何東西被記錄到App_Data。然後我在網上尋求幫助,並安裝了Elmah.Contrib.WebApi。但這仍然沒有幫助。以下是我的配置文件。asp.net web api elmah不會將錯誤記錄到xml文件

'的web.config

<?xml version="1.0" encoding="utf-8"?> 
 
<configuration> 
 
    <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" /> 
 
    </configSections> 
 
    <connectionStrings> 
 
    <!-->add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-CashFlowManagement.Web-20161209090731.mdf;Initial Catalog=aspnet-CashFlowManagement.Web-20161209090731;Integrated Security=True" 
 
     providerName="System.Data.SqlClient" /--> 
 
    <add name="CashFlowDb" connectionString="data source=LENOVO-PC;initial catalog=CashFlow;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /> 
 
    </connectionStrings> 
 
    <appSettings></appSettings> 
 
    <system.web> 
 
    <authentication mode="None" /> 
 
    <compilation debug="true" targetFramework="4.5.2" /> 
 
    <httpRuntime targetFramework="4.5.2" /> 
 
    </system.web> 
 
    <system.webServer> 
 
    <modules> 
 
     <remove name="FormsAuthentication" /> 
 
    </modules> 
 
    <handlers> 
 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
 
     <remove name="OPTIONSVerbHandler" /> 
 
     <remove name="TRACEVerbHandler" /> 
 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
 
    </handlers> 
 
    </system.webServer> 
 
    <runtime> 
 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /> 
 
     <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" /> 
 
     <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" /> 
 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /> 
 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> 
 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
 
     <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
 
     <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
 
     </dependentAssembly> 
 
     <dependentAssembly> 
 
     <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
 
     <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
 
     </dependentAssembly> 
 
    </assemblyBinding> 
 
    </runtime> 
 
    <entityFramework> 
 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
 
     <parameters> 
 
     <parameter value="mssqllocaldb" /> 
 
     </parameters> 
 
    </defaultConnectionFactory> 
 
    <providers> 
 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
 
    </providers> 
 
    </entityFramework> 
 
    <system.codedom> 
 
    <compilers> 
 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 
 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
 
    </compilers> 
 
    </system.codedom> 
 
</configuration>

`

+0

你應該不要將任何文件寫入虛擬目錄,因爲這可能會導致應用程序回收,因爲有一個文件觀察器監視虛擬目錄下文件的任何更改以執行重新啓動,例如編輯web.config時的情況 –

回答

0

Web.config文件不包含任何ELMAH配置。看看這個ELMAH Tutorial如何開始。缺少配置的問題可能是您的環境不允許PowerShell作爲安裝ELMAH NuGet軟件包的一部分運行。如果您運行Get-ExecutionPolicy,它會返回什麼?

更新:按照指示在Configure elmah.io manually和配置XML文件錯誤日誌:

<elmah> 
    <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" /> 
</elmah> 

作爲替代方案,您可以在安裝之前設置在PowerShell中的執行策略ELMAH:

Set-ExecutionPolicy RemoteSigned 
+0

它返回'限制' –

+0

這就是我的想法:)然後你需要[手動配置ELMAH](http://docs.elmah.io/configure-elmah-io-manually/)。我在示例中設置了elmah.io錯誤日誌,但是應該使用以下代碼替換web.config中的elmah元素: – ThomasArdal

+0