StartUp.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Microsoft.Extensions.Configuration;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Hosting;
  4. using NetMQ.Sockets;
  5. using Serilog;
  6. namespace Iec104ComService
  7. {
  8. public class StartUp
  9. {
  10. public static string Basepath = "D:/Project/test/Iec104ComService/bin/Debug/netcoreapp3.1";
  11. public StartUp()
  12. {
  13. }
  14. public static IHostBuilder CreateHostBuilder(string[] args)
  15. {
  16. Log.Logger = new LoggerConfiguration()
  17. .Enrich.FromLogContext()
  18. .WriteTo.Console()
  19. .WriteTo.File(Basepath + "/log.log",
  20. restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Verbose,
  21. outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] Message:{Message:lj}{NewLine}{Exception}",
  22. rollingInterval: RollingInterval.Day
  23. , retainedFileCountLimit: 30, encoding: System.Text.Encoding.Unicode)
  24. .CreateLogger();
  25. return Host.CreateDefaultBuilder(args)
  26. .ConfigureServices((hostContext, services) =>
  27. {
  28. services.AddHostedService<SendIec104MsgWorker>()
  29. .AddHostedService<GetIec104MsgWorker>()
  30. .AddSingleton(new ConfigurationBuilder().AddJsonFile(Basepath + "/appsetting.json").Build())
  31. .AddSingleton(new PublisherSocket("tcp://*:54300"))
  32. .AddSingleton(new SubscriberSocket("tcp://*:54301"));
  33. }).UseWindowsService();
  34. }
  35. }
  36. }