You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 line
1.5 KiB

  1. using Microsoft.Extensions.Configuration;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.DependencyInjection.Extensions;
  4. using Microsoft.Extensions.Hosting;
  5. using Microsoft.Extensions.Logging;
  6. using System;
  7. using System.Collections.Concurrent;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.Threading.Tasks;
  11. namespace JT808.DotNetty.Hosting
  12. {
  13. class Program
  14. {
  15. static async Task Main(string[] args)
  16. {
  17. var serverHostBuilder = new HostBuilder()
  18. .ConfigureAppConfiguration((hostingContext, config) =>
  19. {
  20. config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
  21. config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
  22. })
  23. .ConfigureLogging((context, logging) =>
  24. {
  25. logging.AddConsole();
  26. logging.SetMinimumLevel(LogLevel.Debug);
  27. })
  28. .ConfigureServices((hostContext, services) =>
  29. {
  30. services.AddSingleton<ILoggerFactory, LoggerFactory>();
  31. services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
  32. // 自定义消息处理业务
  33. services.Replace(new ServiceDescriptor(typeof(JT808MsgIdHandlerBase), typeof(JT808MsgIdCustomHandler), ServiceLifetime.Singleton));
  34. })
  35. .UseJT808Host();
  36. await serverHostBuilder.RunConsoleAsync();
  37. }
  38. }
  39. }