FastTunnel/FastTunnel.Client/Program.cs

57 lines
1.9 KiB
C#
Raw Permalink Normal View History

2022-01-02 00:23:39 +08:00
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://github.com/FastTunnel/FastTunnel/edit/v2/LICENSE
// Copyright (c) 2019 Gui.H
using Microsoft.Extensions.Hosting;
2020-11-01 12:27:29 +08:00
using Microsoft.Extensions.Logging;
2021-08-01 18:32:32 +08:00
using System;
2021-08-07 23:54:48 +08:00
using Microsoft.Extensions.Configuration;
2022-06-23 16:19:27 +08:00
using Serilog;
2022-11-11 22:31:27 +08:00
using FastTunnel.Core.Client.Extensions;
2022-12-03 21:29:17 +08:00
using Serilog.Events;
2024-01-16 13:57:10 +08:00
using Microsoft.Extensions.DependencyInjection;
using FastTunnel.Core.Config;
2019-12-16 10:29:06 +08:00
2022-01-02 00:23:39 +08:00
namespace FastTunnel.Client;
class Program
2019-12-16 10:29:06 +08:00
{
2022-01-02 00:23:39 +08:00
public static void Main(string[] args)
2019-12-16 10:29:06 +08:00
{
2022-12-03 21:29:17 +08:00
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console().WriteTo.File("Logs/log-.log", rollingInterval: RollingInterval.Day)
.CreateBootstrapLogger();
2022-01-02 00:23:39 +08:00
try
2019-12-16 10:29:06 +08:00
{
2022-01-02 00:23:39 +08:00
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
2022-12-03 21:29:17 +08:00
Log.Fatal(ex, "致命异常");
throw;
2019-12-16 10:29:06 +08:00
}
2022-01-02 00:23:39 +08:00
}
2019-12-16 10:29:06 +08:00
2022-01-02 00:23:39 +08:00
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
2022-07-10 22:34:13 +08:00
.UseSerilog((context, services, loggerConfiguration) =>
2022-01-02 00:23:39 +08:00
{
2022-07-10 22:34:13 +08:00
loggerConfiguration.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.WriteTo.Console();
2022-06-23 16:19:27 +08:00
})
.UseWindowsService()
.ConfigureServices((hostContext, services) =>
{
// -------------------FastTunnel START------------------
2022-07-10 22:34:13 +08:00
services.AddFastTunnelClient(hostContext.Configuration.GetSection("FastTunnel"));
2022-06-23 16:19:27 +08:00
// -------------------FastTunnel EDN--------------------
2022-01-02 00:23:39 +08:00
});
2019-12-16 10:29:06 +08:00
}