本文整理汇总了C#中IApplicationBuilder.UseRequestLogger方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseRequestLogger方法的具体用法?C# IApplicationBuilder.UseRequestLogger怎么用?C# IApplicationBuilder.UseRequestLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IApplicationBuilder
的用法示例。
在下文中一共展示了IApplicationBuilder.UseRequestLogger方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureTraceLogging
public void ConfigureTraceLogging(IApplicationBuilder app,
ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Debug;
#if DNX451
var sourceSwitch = new SourceSwitch("LoggingSample");
sourceSwitch.Level = SourceLevels.Critical;
loggerFactory.AddTraceSource(sourceSwitch,
new ConsoleTraceListener(false));
loggerFactory.AddTraceSource(sourceSwitch,
new EventLogTraceListener("Application"));
#endif
app.UseRequestLogger();
app.Run(async context =>
{
if (context.Request.Path.Value.Contains("boom"))
{
throw new Exception("boom!");
}
await context.Response.WriteAsync("Hello World!");
});
}
示例2: ConfigureLogMiddleware
public void ConfigureLogMiddleware(IApplicationBuilder app,
ILoggerFactory loggerfactory)
{
loggerfactory.AddConsole(minLevel: LogLevel.Information);
app.UseRequestLogger();
app.Run(async context =>
{
await context.Response.WriteAsync("Hello from " + _environment);
});
}
示例3: ConfigureLogMiddleware
public void ConfigureLogMiddleware(IApplicationBuilder app,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(minLevel: LogLevel.Debug);
app.UseRequestLogger();
app.Run(async context =>
{
if (context.Request.Path.Value.Contains("boom"))
{
throw new Exception("boom!");
}
await context.Response.WriteAsync("Hello World!");
});
}
示例4: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
loggerFactory.AddDebug();
// Configure the HTTP request pipeline.
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage();
}
else
{
// Add Error handling middleware which catches all application specific errors and
// send the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
app.UseRequestLogger();
// Use prerender middleware
app.UsePrerender();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
// Uncomment the following line to add a route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
});
}
示例5: Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole(minLevel: LogLevel.Information);
loggerFactory.AddDebug();
var logger = loggerFactory.CreateLogger(env.EnvironmentName);
app.UseRequestLogger();
app.MapWhen(context =>
{
return context.Request.Query.ContainsKey("branch");
}, HandleBranch);
app.Run(async context =>
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("Hello from " + env.EnvironmentName);
});
}
示例6: Configure
public void Configure(IApplicationBuilder app)
{
app.UseCors(builder =>
{
builder.AllowAnyHeader();
builder.AllowAnyMethod();
builder.AllowAnyOrigin();
builder.AllowCredentials();
});
// use custom middleware
app.UseRequestLogger();
app.UseAldeloAuthentication(configureOptions: option =>
{
// if false, you have to explicitly point out what AuthenticationScheme in [Authorize]
// like '[Authorize(ActiveAuthenticationSchemes ="Bearer")]'
option.AutomaticAuthenticate = true;
// Challenge will be shown in request header, as default 'WWW-Authenticate: Aldelo.Passport'
// if false, cannot enter AldeloAuthenticationHandler code, will return 401 directly
option.AutomaticChallenge = true;
// if you want to validate below:
// security key (for signature), lifetime, audience and issuer
// these 4 field default value is true
option.TokenValidationParameters.RequireSignedTokens = true;
option.TokenValidationParameters.ValidateSignature = true;
option.TokenValidationParameters.IssuerSigningKey = Utils.SecurityKey;
option.TokenValidationParameters.ValidateLifetime = true;
option.TokenValidationParameters.ValidateIssuer = true;
option.TokenValidationParameters.ValidIssuer = "isu:aldelo.security";
option.TokenValidationParameters.ValidateAudience = true;
option.TokenValidationParameters.ValidAudience = "aud:aldelo.cloud";
/* custom the audience validator
option.TokenValidationParameters.AudienceValidator = (audi, security, vp) =>
{
foreach (var s in audi)
{
if (s == "aud:aldelo.cloud")
{
return true;
}
}
return false;
};
*/
// process events
option.Events = new JwtBearerEvents()
{
OnChallenge = (context) =>
{
return Task.FromResult(false);
},
OnReceivedToken = (context) =>
{
return Task.FromResult(false);
},
OnValidatedToken = (context) =>
{
// give him 'BossClaim' for authorization policy
//context.AuthenticationTicket.Principal.AddIdentity(new ClaimsIdentity(new List<Claim> { new Claim("BossClaim", "I'm boss") }));
return Task.FromResult(false);
},
OnAuthenticationFailed = (context) =>
{
return Task.FromResult(false);
}
};
// if we want a validator instead of default one
//option.SecurityTokenValidators = new List<ISecurityTokenValidator>() { new BlobTokenValidator() };
});
app.UseMvc();
}