是否可以安装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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<target xsi:type="Database"
name="database"
connectionStringName="DefaultConnection"
commandText="INSERT INTO [dbo].[AspNetEventLogs] ([Application], [Logged], [Level],[Message],[UserName],[ServerName],[Port],[Url],[Https],[ServerAddress],[Logger],[Callsite], [Exception]) VALUES (@Application, @Logged, @Level, @Message, @UserName, @ServerName, @Port, @Url, @Https, @ServerAddress, @Logger, @CallSite, @Exception);
">
<parameter name="@application" layout="${appsetting:name=appName}" />
<parameter name="@logged" layout="${date}" />
<parameter name="@level" layout="${level}" />
<parameter name="@message" layout="${message}" />
<parameter name="@username" layout="${identity}" />
<parameter name="@serverName" layout="${aspnet-request:serverVariable=SERVER_NAME}" />
<parameter name="@port" layout="${aspnet-request:serverVariable=SERVER_PORT}" />
<parameter name="@url" layout="${aspnet-request:serverVariable=HTTP_URL}" />
<parameter name="@https" layout="${when:inner=1:when='${aspnet-request:serverVariable=HTTPS}' == 'on'}${when:inner=0:when='${aspnet-request:serverVariable=HTTPS}' != 'on'}" />
<parameter name="@serverAddress" layout="${aspnet-request:serverVariable=LOCAL_ADDR}" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@callSite" layout="${callsite}" />
<parameter name="@exception" layout="${exception:tostring}" />
</target>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Trace" writeTo="database" />
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>
但是,当前其中某些列未正确填充。服务器名称为空,应用程序名称为空。我希望在同一解决方案中将其用于多个项目。
答案 0 :(得分:0)
如果将nlog.config部署在正确的文件夹中并且其他项目可以访问“ httpcontext”(例如其他ASP.NET项目),则Tt应该可以工作
关于空值,请检查内部日志:https://github.com/nlog/NLog/wiki/Internal-logging
请注意,${aspnet-request}
需要NLog.Web或NLog.Web.AspNetCore