Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为nlog创建配置节处理程序时出错:设置属性时出错';布局';关于NLog.Targets.DatabaseParameterInfo_C#_Database_Logging_Nlog - Fatal编程技术网

C# 为nlog创建配置节处理程序时出错:设置属性时出错';布局';关于NLog.Targets.DatabaseParameterInfo

C# 为nlog创建配置节处理程序时出错:设置属性时出错';布局';关于NLog.Targets.DatabaseParameterInfo,c#,database,logging,nlog,C#,Database,Logging,Nlog,我有(我认为是)一个非常简单的NLog数据库记录器,没有任何异国情调或激动人心的东西,但我被骂了,我没有任何关于问题所在的信息 我已将NLog连接到Common。记录方式如下: <common> <logging> <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog40"> <arg

我有(我认为是)一个非常简单的NLog数据库记录器,没有任何异国情调或激动人心的东西,但我被骂了,我没有任何关于问题所在的信息

我已将NLog连接到Common。记录方式如下:

<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的配置节处理程序时出错:在nlog.Targets.DatabaseParameterInfo上设置属性“Layout”时出错 源错误: 第86行: 第87行:
第88行:稍微晚一点可能会有帮助:

如果您使用的是NLog>4.0,则ASP.NET渲染器位于NLog.Web中。因此,您需要将其与Nuget软件包一起添加,并如下所示引用它:

<extensions>
    <add assembly="NLog.Web" />
</extensions>

<extensions>
    <add assembly="NLog.Web" />
</extensions>
<parameter name="@Username" layout="${aspnet-user-identity}" />