I won’t go too much into the details of my project, but I am implementing simple logging into a .txt file. I am using NLog as a provider. My issue resides with the nlog.config file:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
internalLogFile="c:tempinternal-nlog-AspNetCore.txt">
<extensions>
<add assembly="NLog.Web.AspNetCore" />
</extensions>
<targets>
<target xsi:type="File" name="auditlog" filename="{basedir}LogsMain${shortdate}.txt" layout="[ApiAuditLog] | Logger: ${logger} | ${time} | Details: ${message}" />
<target xsi:type="File" name="servicelog" filename="{basedir}LogsMain${shortdate}.txt" layout="[ServiceLog] | Logger: ${logger} | ${time} | Details: ${message}" />
<target xsi:type="File" name="exceptionfile" filename="{basedir}LogsExceptions${shortdate}.txt" layout="[ExceptionLog] | Logger: ${logger} | ${time} | Details: ${message}"/>/>
</targets>
<rules>
<logger name="Microsoft.*" maxLevel="info" final="true" />
<logger name="GameStore.API.Middlewares.RequestResponseLoggingMiddleware*" minlevel="Info" writeTo="auditlog" final="true"/>
<logger name="GameStore.BLL.Services*" minlevel="Info" writeTo="servicelog" final="true"/>
<logger name="*ExceptionHandlingMiddleware*" minlevel="Error" writeto="exceptionfile" />
</rules>
</nlog>
The issue is that the auditlog does not get logged, even though I checked with the debugger, and the ILogger instance itself is enabled.
I all sorts of stuff. I tried removing everything else from the nlog.config file and leaving only the details for the auditlogging. I tried only passing a test string to the ILogger instance (usually it takes a json formatted string). I tried rewiring the namespaces….
ika giorgadze is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.