2014-12-05 64 views
0

我一直試圖在Asp.Net Web Api 2.2應用程序中將NLog作爲一個跟蹤編寫器來實現。這是我的web.config:NLog不寫在Asp.Net Web Api App中

<configSections> 
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> 
</configSections> 
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" throwExceptions="true" internalLogFile="c:\file.txt"> 
<targets> 
    <target name="logfile" xsi:type="File" fileName="${basedir}/Logs/log.txt"/> 
    <rules> 
    <logger name="*" minlevel="Info" writeTo="logfile"/> 
    </rules> 
</targets> 

在調試過程中這一點,如果我使用IIS Express作爲主機工作正常,但如果我設置的項目中使用本地IIS失敗了System.UnauthorizedAccessException。我也以管理員身份運行VS 2013。

回答

0

您應該檢查在本地IIS中配置用於運行Web應用程序的appdomain的用戶是否有足夠的訪問權限來寫入${basedir}/Logs目錄。

請確保您可以從您的應用程序運行此代碼:

File.WriteAllText(
    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs\test.txt"), 
    "Some content"); 

當你能夠做到這一點,你也可以做日誌