在 .net core 2.2 中,有一个默认的 json,状态码为 415,如
{
"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13",
"title":"Unsupported Media Type",
"status":415,
"traceId":"8000003e-0001-f500-b63f-84710c7967bb"
}
Run Code Online (Sandbox Code Playgroud)
我不知道这个 JSON 是怎么来的。我按照下面的例子重写json
但是我得到了不同的结果,它在原始 json 中添加了一个部分。这是我的 Wireshark 结果
HTTP/1.1 415 不支持的媒体类型传输编码:分块
内容类型:应用程序/问题+json;字符集=utf-8 服务器:
Microsoft-IIS/10.0 X-Powered-By:ASP.NET 日期:2019 年 5 月 6 日星期一 09:03:56 GMT
{
"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13",
"title":"Unsupported Media Type",
"status":415,
"traceId":"8000002c-0002-fb00-b63f-84710c7967bb"
}
{
"data":"this is custom message"
}
Run Code Online (Sandbox Code Playgroud)
过滤器:
public class MediaTypeResouceFilter : Attribute, IResourceFilter
{
public void OnResourceExecuting(ResourceExecutingContext context)
{
}
public void OnResourceExecuted(ResourceExecutedContext context)
{
if (context.HttpContext.Response.StatusCode == 415)
{
var …Run Code Online (Sandbox Code Playgroud) 以下是我的日志
[2019-05-07 15:55:38.4270][PC-20170829ROEW][信息]我记录的日志
[2019-05-07 15:55:38.4929][PC-20170829ROEW][Info] 路线与 {action = >"Get",controller = "Values"} 匹配。执行动作 >QunarFlight.Web.Controllers.ValuesController.Get (QunarFlight.Web)
[2019-05-07 15:55:38.5798][PC-20170829ROEW][Info] 执行操作方法 >QunarFlight.Web.Controllers.ValuesController.Get (QunarFlight.Web) - 验证 >state: Valid
[2019-05-07 15:55:38.6066][PC-20170829ROEW][Info]执行操作方法> QunarFlight.Web.Controllers.ValuesController.Get(QunarFlight.Web),返回>结果Microsoft.AspNetCore.Mvc.ObjectResult 22.6363 毫秒。
[2019-05-07 15:55:38.6066][PC-20170829ROEW][Info] 执行 ObjectResult,>写入“System.String[]”类型的值。
我想关闭所有Microsoft默认日志(最后四条记录),只保留我记录的日志(第一条记录)。我修改 appsettings.json 以下内容
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore.Hosting": "Warning",
"Microsoft.AspNetCore.Routing": "Warning",
"Microsoft.AspNetCore.Mvc": "Warning"
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我记录的日志将不会输出。如果我删除“Microsoft.AspNetCore.Mvc”:“警告”我记录的日志将被输出。我应该如何修改它?
应用程序设置.json
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore.Hosting": "Warning",
"Microsoft.AspNetCore.Routing": "Warning",
"Microsoft.AspNetCore.Mvc": "Warning"
}
Run Code Online (Sandbox Code Playgroud)
在Startup.cs中配置
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
env.ConfigureNLog("NLog.config");
loggerFactory.AddNLog(); …Run Code Online (Sandbox Code Playgroud)