【发布时间】:2018-07-30 11:13:09
【问题描述】:
我正在使用 ASP .Net Core 2.1 WebAPI。是否可以使用 NLog 的配置记录当前的请求体和请求头?
<?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"
autoReload="true">
<extensions>
<add prefix="custom" assembly="Pepper" />
</extensions>
<variable name="log-header"
value="Time: [${date}]${newline}
Operation: ${aspnet-request-method} ${aspnet-request-url:IncludeHost=true:IncludePort=true:IncludeQueryString=true}${newline}
Headers:${aspnet-request-headers}${newline}
Body:${aspnet-request-body}"/>
<targets>
<target name="exceptionFile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File"
encoding="utf-8"
fileName="exception_log.txt"
archiveAboveSize="10000000"
archiveNumbering="Sequence"
maxArchiveFiles="10"
layout="${log-header}${newline}${message}${newline}${newline}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="exceptionFile" />
</rules>
</nlog>
【问题讨论】:
-
我强烈建议不要这样做,因为它是一个主要的安全问题(对性能和资源使用也不利)。如果你真的想调试它,请使用 wireshark 或其他转储流量的工具
标签: asp.net-core nlog asp.net-core-webapi