NLog:找不到LayoutRenderer:'aspnet-user-identity

时间:2019-10-09 15:35:25

标签: oracle nlog appsettings

我尝试将NLog实施到我的.NET Core Api Web服务中。 我想登录到Oracle数据库。所有这些都可以通过nlog.config XML文件很好地工作。

但是目标是将NLog config实施到appsettings.json中,从而出现问题。 我在标题中设置了错误:

  

找不到LayoutRenderer:'aspnet-user-identity

我的配置文件是这样的:

"NLog": {
    "autoReload": true,
    "throwConfigExceptions": true,
    "internalLogLevel": "info",
    "internalLogFile": "c:/app/log/dev/internal-appsetting-nlog.txt",
    "extensions": {
        "NLog.Extensions.Logging": {
            "assembly": [
                "NLog.Extensions.Logging",
                "NLog.Web.AspNetCore"
            ]
        }
    },
    "variables": {
        "var_logdir": "c:/app/log/dev"
    },
    "default-wrapper": {
        "type": "AsyncWrapper",
        "overflowAction": "Block"
    },
    "targets": {
        "all-file": {
            "type": "File",
            "fileName": "${var_logdir}/nlog-all-${shortdate}.log",
            "layout": {
                "type": "JsonLayout",
                "Attributes": [
                    {
                        "name": "timestamp",
                        "layout": "${date:format=o}"
                    },
                    {
                        "name": "level",
                        "layout": "${level}"
                    },
                    {
                        "name": "logger",
                        "layout": "${logger}"
                    },
                    {
                        "name": "message",
                        "layout": "${message:raw=true}"
                    },
                    {
                        "name": "properties",
                        "encode": false,
                        "layout": {
                            "type": "JsonLayout",
                            "includeallproperties": "true"
                        }
                    }
                ]
            }
        },
        "db": {
            "type": "Database",
            "commandText": "INSERT INTO logtable (LOGLEVEL,LOGGER,MESSAGE,MACHINENAME,USERNAME,CALLSITE, THREADID,EXCEPTIONMESSAGE,STACKTRACE,SESSIONID) VALUES (:pLEVEL,:pLOGGER,:pMESSAGE,:pMACHINENAME, :pCALLSITE,:pTHREADID,:pEXCEPTIONMESSAGE,:pSTACKTRACE)",
            "parameters": [
                {
                    "name": "@pLEVEL",
                    "layout": "${level}"
                },
                {
                    "name": "@pLOGGER",
                    "layout": "${logger}"
                },

                {
                    "name": "@pMESSAGE",
                    "layout": "${message}"
                },
                {
                    "name": "@pMACHINENAME",
                    "layout": "${machinename}"
                },
                {
                    "name": "@pUSERNAME",
                    "layout": "${aspnet-user-identity}"
                },
                {
                    "name": "@pCALLSITE",
                    "layout": "${callsite:filename=true}"
                },
                {
                    "name": "@pTHREADID",
                    "layout": "${threadid}"
                },
                {
                    "name": "@pEXCEPTIONMESSAGE",
                    "layout": "${exception}"
                },
                {
                    "name": "@pSTACKTRACE",
                    "layout": "${stacktrace}"
                },
                {
                    "name": "@pSESSIONID",
                    "layout": "${aspnet-sessionid}"
                }
            ],
            "dbProvider": "Oracle.ManagedDataAccess.Client.OracleConnection, Oracle.ManagedDataAccess",
            "connectionString": "xxxxxxxxxxxx"
        }
    },
    "rules": [
        {
            "logger": "*",
            "minLevel": "Trace",
            "writeTo": "all-file"
        },
        {
            "logger": "*",
            "minLevel": "Trace",
            "writeTo": "db"
        },
        {
            "logger": "Microsoft.*",
            "maxLevel": "Info",
            "final": true
        }
    ]
},

内部调试器报告:

2019-10-09 16:48:48.6665 Info Adding target AsyncTargetWrapper(Name=all-file)
2019-10-09 16:48:48.7859 Warn Error when setting property 'Layout' on 'NLog.Targets.DatabaseParameterInfo' Exception: System.ArgumentException: LayoutRenderer cannot be found: 'aspnet-user-identity'. Is NLog.Web not included?
   at NLog.Config.Factory`2.CreateInstance(String itemName)
   at NLog.Layouts.LayoutParser.GetLayoutRenderer(ConfigurationItemFactory configurationItemFactory, String name)
   at NLog.Layouts.LayoutParser.ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, SimpleStringReader stringReader)
   at NLog.Layouts.LayoutParser.CompileLayout(ConfigurationItemFactory configurationItemFactory, SimpleStringReader sr, Boolean isNested, String& text)
   at NLog.Layouts.SimpleLayout.set_Text(String value)
   at NLog.Internal.PropertyHelper.TryNLogSpecificConversion(Type propertyType, String value, Object& newValue, ConfigurationItemFactory configurationItemFactory)
   at NLog.Internal.PropertyHelper.SetPropertyFromString(Object obj, String propertyName, String value, ConfigurationItemFactory configurationItemFactory)

${aspnet-sessionid}上发生错误。如果我注释掉这两种布局,一切都会很好。

我在GitHub问题报告中发现了不同的东西,但我尝试的全部都是失败。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

未知的"C:\path\to\php-7.2.23-Win32-VC15-x64\php.exe" -d memory_limit=-1 "C:/path/to/composer.phar" update 可能是您的扩展程序存在的问题:

aspnet-user-identity

您可以尝试以上建议吗?

P.S。更新了wiki,以包含多个“扩展名”的示例