为 nlog 创建配置节处理程序时出错:在 NLog.Targets.DatabaseParameterInfo 上设置 属性 'Layout' 时出错
Error occurred creating the configuration section handler for nlog: Error when setting property 'Layout' on NLog.Targets.DatabaseParameterInfo
我有(我认为是)一个非常简单的 NLog 数据库记录器,没有任何奇特或令人兴奋的东西,但我被大吼大叫,而且我没有任何关于问题所在的信息。
我已将 NLog 连接到 Common.Logging,如下所示:
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog40">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<nlog
internalLogLevel="Trace"
internalLogFile="c:\logs\myservice.api.nlog.log"
throwExceptions="true">
<extensions>
<add assembly="NLog.Extended" />
</extensions>
<targets>
<target
type="Database"
name="database"
dbProvider="mssql"
commandType="Text"
connectionStringName="MyServiceDbConnection"
commandText="INSERT INTO dbo.LOGS (Machine, ExecutingAssembly, UtcTimestamp, Source, Thread, Severity, Username, Message) VALUES (@Machine, @ExecutingAssembly, @UtcTimestamp, @Source, @Thread, @Severity, @Username, @Message);">
<parameter name="@Machine" layout="${machinename}" />
<parameter name="@ExecutingAssembly" layout="${literal:text=MyService.Api}" />
<parameter name="@UtcTimestamp" layout="${date:universalTime=true}" />
<parameter name="@Source" layout="${logger}" />
<parameter name="@Thread" layout="${threadname}" />
<parameter name="@Severity" layout="${level:uppercase=true}" />
<parameter name="@Username" layout="${aspnet-user-identity}" />
<parameter name="@Message" layout="${message} ${exception:format=ToString}" />
</target>
</targets>
<rules>
<logger name="*" minLevel="Debug" writeTo="database" />
</rules>
</nlog>
当我尝试 运行 我的 api 应用程序时,我收到以下错误消息:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: An error occurred creating the configuration section handler for nlog: Error when setting property 'Layout' on NLog.Targets.DatabaseParameterInfo
Source Error:
Line 86: </logging>
Line 87: </common>
Line 88: <nlog
Line 89: internalLogLevel="Trace"
Line 90: internalLogFile="c:\logs\myservice.api.nlog.log"
我的内部 NLog 日志不是很有帮助:
2015-08-13 08:21:05.1643 Info Loading assembly name: NLog.Extended
2015-08-13 08:21:05.1643 Debug ScanAssembly('NLog.Extended, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.name' to 'database'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.dbProvider' to 'mssql'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.commandType' to 'Text'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.connectionStringName' to 'MyServiceDbConnection'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.commandText' to 'INSERT INTO dbo.LOGS (Machine, ExecutingAssembly, UtcTimestamp, Source, Thread, Severity, Username, Message) VALUES (@Machine, @ExecutingAssembly, @UtcTimestamp, @Source, @Thread, @Severity, @Username, @Message);'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseParameterInfo.name' to '@Machine'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseParameterInfo.layout' to '${machinename}'
2015-08-13 08:21:05.1753 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1753 Trace Scanning MachineNameLayoutRenderer 'Layout Renderer: ${machinename}'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseParameterInfo.name' to '@ExecutingAssembly'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${literal:text=MyService.Api}'
2015-08-13 08:21:05.1892 Debug Setting 'LiteralLayoutRenderer.text' to 'Onlife.Globalization.Api'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@UtcTimestamp'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${date:universalTime=true}'
2015-08-13 08:21:05.1892 Debug Setting 'DateLayoutRenderer.universalTime' to 'true'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning DateLayoutRenderer 'Layout Renderer: ${date}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Source'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${logger}'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning LoggerNameLayoutRenderer 'Layout Renderer: ${logger}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Thread'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${threadname}'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning ThreadNameLayoutRenderer 'Layout Renderer: ${threadname}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Severity'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${level:uppercase=true}'
2015-08-13 08:21:05.1892 Debug Setting 'UppercaseLayoutRendererWrapper.uppercase' to 'true'
2015-08-13 08:21:05.1892 Trace Wrapping LevelLayoutRenderer with UppercaseLayoutRendererWrapper
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning LevelLayoutRenderer 'Layout Renderer: ${level}'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning UppercaseLayoutRendererWrapper 'Layout Renderer: ${uppercase}'
2015-08-13 08:21:05.1892 Trace Scanning SimpleLayout ''''
2015-08-13 08:21:05.1892 Trace Scanning LevelLayoutRenderer 'Layout Renderer: ${level}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Username'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${aspnet-user-identity}'
2015-08-13 08:21:15.5407 Info Shutting down logging...
2015-08-13 08:21:15.5407 Info Logger has been shut down.
这里没有其他错误消息或问题的指示。我做错了什么?
晚了一点可能会有帮助:
如果您使用的是 NLog > 4.0,则 ASP.NET 渲染在 NLog.Web 中。所以你需要用 Nuget 包添加它并引用它如下:
<extensions>
<add assembly="NLog.Web" />
</extensions>
这就是全部,因为您正在使用以下参数:
<parameter name="@Username" layout="${aspnet-user-identity}" />
更多信息在这里:http://nlog-project.org/2015/06/13/NLog-Extended_NLog-Web_and_NLog-Windows-Forms.html
我有(我认为是)一个非常简单的 NLog 数据库记录器,没有任何奇特或令人兴奋的东西,但我被大吼大叫,而且我没有任何关于问题所在的信息。
我已将 NLog 连接到 Common.Logging,如下所示:
<common>
<logging>
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog40">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<nlog
internalLogLevel="Trace"
internalLogFile="c:\logs\myservice.api.nlog.log"
throwExceptions="true">
<extensions>
<add assembly="NLog.Extended" />
</extensions>
<targets>
<target
type="Database"
name="database"
dbProvider="mssql"
commandType="Text"
connectionStringName="MyServiceDbConnection"
commandText="INSERT INTO dbo.LOGS (Machine, ExecutingAssembly, UtcTimestamp, Source, Thread, Severity, Username, Message) VALUES (@Machine, @ExecutingAssembly, @UtcTimestamp, @Source, @Thread, @Severity, @Username, @Message);">
<parameter name="@Machine" layout="${machinename}" />
<parameter name="@ExecutingAssembly" layout="${literal:text=MyService.Api}" />
<parameter name="@UtcTimestamp" layout="${date:universalTime=true}" />
<parameter name="@Source" layout="${logger}" />
<parameter name="@Thread" layout="${threadname}" />
<parameter name="@Severity" layout="${level:uppercase=true}" />
<parameter name="@Username" layout="${aspnet-user-identity}" />
<parameter name="@Message" layout="${message} ${exception:format=ToString}" />
</target>
</targets>
<rules>
<logger name="*" minLevel="Debug" writeTo="database" />
</rules>
</nlog>
当我尝试 运行 我的 api 应用程序时,我收到以下错误消息:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: An error occurred creating the configuration section handler for nlog: Error when setting property 'Layout' on NLog.Targets.DatabaseParameterInfo
Source Error:
Line 86: </logging>
Line 87: </common>
Line 88: <nlog
Line 89: internalLogLevel="Trace"
Line 90: internalLogFile="c:\logs\myservice.api.nlog.log"
我的内部 NLog 日志不是很有帮助:
2015-08-13 08:21:05.1643 Info Loading assembly name: NLog.Extended
2015-08-13 08:21:05.1643 Debug ScanAssembly('NLog.Extended, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.name' to 'database'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.dbProvider' to 'mssql'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.commandType' to 'Text'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.connectionStringName' to 'MyServiceDbConnection'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseTarget.commandText' to 'INSERT INTO dbo.LOGS (Machine, ExecutingAssembly, UtcTimestamp, Source, Thread, Severity, Username, Message) VALUES (@Machine, @ExecutingAssembly, @UtcTimestamp, @Source, @Thread, @Severity, @Username, @Message);'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseParameterInfo.name' to '@Machine'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseParameterInfo.layout' to '${machinename}'
2015-08-13 08:21:05.1753 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1753 Trace Scanning MachineNameLayoutRenderer 'Layout Renderer: ${machinename}'
2015-08-13 08:21:05.1753 Debug Setting 'DatabaseParameterInfo.name' to '@ExecutingAssembly'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${literal:text=MyService.Api}'
2015-08-13 08:21:05.1892 Debug Setting 'LiteralLayoutRenderer.text' to 'Onlife.Globalization.Api'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning LiteralLayoutRenderer 'Layout Renderer: ${literal}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@UtcTimestamp'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${date:universalTime=true}'
2015-08-13 08:21:05.1892 Debug Setting 'DateLayoutRenderer.universalTime' to 'true'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning DateLayoutRenderer 'Layout Renderer: ${date}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Source'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${logger}'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning LoggerNameLayoutRenderer 'Layout Renderer: ${logger}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Thread'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${threadname}'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning ThreadNameLayoutRenderer 'Layout Renderer: ${threadname}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Severity'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${level:uppercase=true}'
2015-08-13 08:21:05.1892 Debug Setting 'UppercaseLayoutRendererWrapper.uppercase' to 'true'
2015-08-13 08:21:05.1892 Trace Wrapping LevelLayoutRenderer with UppercaseLayoutRendererWrapper
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning LevelLayoutRenderer 'Layout Renderer: ${level}'
2015-08-13 08:21:05.1892 Trace FindReachableObject<NLog.Internal.IRenderable>:
2015-08-13 08:21:05.1892 Trace Scanning UppercaseLayoutRendererWrapper 'Layout Renderer: ${uppercase}'
2015-08-13 08:21:05.1892 Trace Scanning SimpleLayout ''''
2015-08-13 08:21:05.1892 Trace Scanning LevelLayoutRenderer 'Layout Renderer: ${level}'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.name' to '@Username'
2015-08-13 08:21:05.1892 Debug Setting 'DatabaseParameterInfo.layout' to '${aspnet-user-identity}'
2015-08-13 08:21:15.5407 Info Shutting down logging...
2015-08-13 08:21:15.5407 Info Logger has been shut down.
这里没有其他错误消息或问题的指示。我做错了什么?
晚了一点可能会有帮助:
如果您使用的是 NLog > 4.0,则 ASP.NET 渲染在 NLog.Web 中。所以你需要用 Nuget 包添加它并引用它如下:
<extensions>
<add assembly="NLog.Web" />
</extensions>
这就是全部,因为您正在使用以下参数:
<parameter name="@Username" layout="${aspnet-user-identity}" />
更多信息在这里:http://nlog-project.org/2015/06/13/NLog-Extended_NLog-Web_and_NLog-Windows-Forms.html