Program.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // See https://aka.ms/new-console-template for more information
  2. using System.Net;
  3. using Microsoft.AspNetCore.Connections;
  4. Console.WriteLine("Hello, World!");
  5. var host = Host.CreateDefaultBuilder()
  6. //.ConfigureLogging(logging =>
  7. //{
  8. // logging.ClearProviders(); // 清除默认日志提供者(可选)
  9. // logging.AddProvider(new LoggerProvider(logger)); // 添加自定义日志提供者
  10. //})
  11. .ConfigureWebHostDefaults(webBuilder =>
  12. {
  13. webBuilder
  14. .UseUrls() //消除警告 Microsoft.AspNetCore.Server.Kestrel[0] Overriding address(es) 'https://localhost:5001/, http://localhost:5000/'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
  15. //.Configure(app =>
  16. //{
  17. // // 防止启动时报错 No application configured
  18. // // 没用🙄 无法取消日志 No action descriptors found. This may indicate an incorrectly configured application or missing application parts. To learn more, visit https://aka.ms/aspnet/mvc/app-parts
  19. // //app.Use(async (HttpContext context, RequestDelegate next) => context.Response.WriteAsync("Hello from Kestrel!"));
  20. //})
  21. .UseKestrel(kop =>
  22. {
  23. kop.Listen(new IPEndPoint(IPAddress.Any, 8000),
  24. lop => lop.Use(
  25. async (ConnectionContext context, ConnectionDelegate next) => await connectionHandler(context)
  26. )
  27. );
  28. });
  29. })
  30. .Build();
  31. await host.StartAsync();
  32. static async Task<object> connectionHandler(ConnectionContext connectionContext)
  33. {
  34. throw new NotImplementedException();
  35. }