将 NLog 与 .Net Core 一起使用时,aspnet-request:serverVariable 的任何替代方案?
Any alternatives to aspnet-request:serverVariable when using NLog with .Net Core?
如 NLog GitHub 所述,.Net Core 不支持 ${aspnet-request:serverVariable=String}
布局渲染器。
该文档没有提供 serverVariable 下可用的许多变量的替代方法。
我的问题是,还有其他选择吗?喜欢访问远程地址、服务器名称、端口等?还是我只需要编写一堆自定义布局渲染器 documented here 并依赖手动注入所有内容?
对于 ASP.NET 核心,有许多新的布局渲染。原因是 ASP.NET 核心的 API 非常不同,无法像 ASP.NET 那样读取服务器变量(所以 non-core)
ASP.NETCore 目前有 13 个布局渲染,渲染了请求的一部分。
- ${aspnet-request} - ASP.NET 请求变量。
- ${aspnet-request-contenttype} - ASP.NET Content-Type header(例如 application/json)
- ${aspnet-request-cookie} - ASP.NET 请求 cookie 内容。
- ${aspnet-request-form} - ASP.NET请求表单内容。
- ${aspnet-request-headers} - ASP.NET Header key/value 对.
- ${aspnet-request-host} - ASP.NET 请求主机
- ${aspnet-request-ip} - 客户端 IP。
- ${aspnet-request-method} - ASP.NET 请求方法(GET、POST 等)。
- ${aspnet-request-posted-body} - ASP.NET posted body / payload
- ${aspnet-request-查询字符串} - ASP.NET 请求查询字符串。
- ${aspnet-request-推荐人} - ASP.NET 请求推荐人。
- ${aspnet-request-url} - ASP.NET 请求 URL。
- ${aspnet-request-useragent} - ASP.NET 请求用户代理。
另见 https://nlog-project.org/config/?tab=layout-renderers&search=package:nlog.web.aspnetcore
如果您需要其他东西,您确实可以创建一个自定义渲染器。如果您需要 http 请求,您可以使用:
AspNetLayoutRendererBase.Register("aspnet-request-myrenderer", (logevent, httpcontext, config) => ... );
为此您需要参考 NLog.Web.AspNetCore 包。
如 NLog GitHub 所述,.Net Core 不支持 ${aspnet-request:serverVariable=String}
布局渲染器。
该文档没有提供 serverVariable 下可用的许多变量的替代方法。
我的问题是,还有其他选择吗?喜欢访问远程地址、服务器名称、端口等?还是我只需要编写一堆自定义布局渲染器 documented here 并依赖手动注入所有内容?
对于 ASP.NET 核心,有许多新的布局渲染。原因是 ASP.NET 核心的 API 非常不同,无法像 ASP.NET 那样读取服务器变量(所以 non-core)
ASP.NETCore 目前有 13 个布局渲染,渲染了请求的一部分。
- ${aspnet-request} - ASP.NET 请求变量。
- ${aspnet-request-contenttype} - ASP.NET Content-Type header(例如 application/json)
- ${aspnet-request-cookie} - ASP.NET 请求 cookie 内容。
- ${aspnet-request-form} - ASP.NET请求表单内容。
- ${aspnet-request-headers} - ASP.NET Header key/value 对.
- ${aspnet-request-host} - ASP.NET 请求主机
- ${aspnet-request-ip} - 客户端 IP。
- ${aspnet-request-method} - ASP.NET 请求方法(GET、POST 等)。
- ${aspnet-request-posted-body} - ASP.NET posted body / payload
- ${aspnet-request-查询字符串} - ASP.NET 请求查询字符串。
- ${aspnet-request-推荐人} - ASP.NET 请求推荐人。
- ${aspnet-request-url} - ASP.NET 请求 URL。
- ${aspnet-request-useragent} - ASP.NET 请求用户代理。
另见 https://nlog-project.org/config/?tab=layout-renderers&search=package:nlog.web.aspnetcore
如果您需要其他东西,您确实可以创建一个自定义渲染器。如果您需要 http 请求,您可以使用:
AspNetLayoutRendererBase.Register("aspnet-request-myrenderer", (logevent, httpcontext, config) => ... );
为此您需要参考 NLog.Web.AspNetCore 包。