Visual studio NLog未在Asp.Net Web Api应用程序中写入
我一直在尝试在Asp.NETWebAPI2.2应用程序中实现NLog作为跟踪编写器。这是我的web.config:Visual studio NLog未在Asp.Net Web Api应用程序中写入,visual-studio,asp.net-web-api,nlog,Visual Studio,Asp.net Web Api,Nlog,我一直在尝试在Asp.NETWebAPI2.2应用程序中实现NLog作为跟踪编写器。这是我的web.config: <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> </configSections> <nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml
<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,则系统将失败。UnauthorizedAccessException。我也是以管理员的身份运行VS 2013。您应该检查在本地IIS中配置用于运行web应用程序的appdomain的用户是否具有足够的访问权限来写入
${basedir}/Logs
目录
请确保您可以从应用程序运行以下代码:
File.WriteAllText(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs\test.txt"),
"Some content");
当您能够做到这一点时,您还可以进行日志记录