728x90
반응형
728x170
▶ Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace TestProject
{
/// <summary>
/// 시작
/// </summary>
public class Startup
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 구성 - Configuration
/// <summary>
/// 구성
/// </summary>
public IConfiguration Configuration { get; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - Startup(configuration)
/// <summary>
/// 생성자
/// </summary>
/// <param name="configuration">구성</param>
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 서비스 컬렉션 구성하기 - ConfigureServices(services)
/// <summary>
/// 서비스 컬렉션 구성하기
/// </summary>
/// <param name="services">서비스 컬렉션</param>
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthorization();
}
#endregion
#region 구성하기 - Configure(app, logger)
/// <summary>
/// 구성하기
/// </summary>
/// <param name="app">애플리케이션 빌더</param>
/// <param name="logger">로그 기록기</param>
public void Configure(IApplicationBuilder app, ILogger<Startup> logger)
{
// 인라인 미들웨어 1
app.Use
(
next => async context =>
{
Stopwatch stopwatch = Stopwatch.StartNew();
await next(context);
stopwatch.Stop();
logger.LogInformation($"TIME 1 : {stopwatch.ElapsedMilliseconds}ms");
}
);
app.UseRouting();
// 인라인 미들웨어 2
app.Use
(
next => async context =>
{
Stopwatch stopwatch = Stopwatch.StartNew();
await next(context);
stopwatch.Stop();
logger.LogInformation($"TIME 2 : {stopwatch.ElapsedMilliseconds}ms");
}
);
app.UseAuthorization();
// 인라인 미들웨어 3
app.Use
(
next => async context =>
{
Stopwatch stopwatch = Stopwatch.StartNew();
await next(context);
stopwatch.Stop();
logger.LogInformation($"TIME 3 : {stopwatch.ElapsedMilliseconds}ms");
}
);
app.UseEndpoints
(
endpoints =>
{
endpoints.MapGet
(
"/",
async context =>
{
await context.Response.WriteAsync("Timing test.");
}
);
}
);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요