我在项目中添加了NLog。按照说明,我创建了NLog.config文件。
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}"
fileName="${basedir}/${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
然后只需记录一些内容。
var logger = LogManager.GetCurrentClassLogger();
logger.Info("xxxx");
开发者web服务器工作正常,但是当我将应用程序发布到IIS时,没有生成任何日志。
${basedir}/${shortdate}.log
的写入权限? - Rich O'Kelly${basedir}/files/${shortdate}.log
,其中 files 目录具有写入权限。 - user49126