/// <summary> /// /// </summary> /// <param name="args"></param> public static void Main(string[] args) { LocalInfo.ServerIp = Environment.GetEnvironmentVariable("HOST_IP"); LocalInfo.SlbIp = Environment.GetEnvironmentVariable("SLB_IP"); if (string.IsNullOrWhiteSpace(LocalInfo.ServerIp)) { LocalInfo.ServerIp = IPAddressHelper.GetLocalIP(); } CreateHostBuilder(args).Build().Run(); }
public static int Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) .MinimumLevel.Override("System", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console( outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code) .CreateLogger(); try { LocalInfo.ServerIp = Environment.GetEnvironmentVariable("HOST_IP"); LocalInfo.SlbIp = Environment.GetEnvironmentVariable("SLB_IP"); if (string.IsNullOrWhiteSpace(LocalInfo.ServerIp)) { LocalInfo.ServerIp = IPAddressHelper.GetLocalIP(); } var host = CreateHostBuilder(args).Build(); #region 初始化数据 //Log.Information("Seeding database..."); //var config = host.Services.GetRequiredService<IConfiguration>(); //var connectionString = config.GetConnectionString("DefaultConnection"); //SeedData.EnsureSeedData(connectionString); //Log.Information("Done seeding database."); #endregion Log.Information("Starting host..."); host.Run(); return(0); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly."); return(1); } finally { Log.CloseAndFlush(); } }
public static string GetIPAddress([NotNull] this HttpRequest thisValue) { string ipStr = thisValue.Headers["HTTP_CF_CONNECTING_IP"]; if (string.IsNullOrEmpty(ipStr)) { ipStr = thisValue.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"]; } if (string.IsNullOrEmpty(ipStr)) { ipStr = thisValue.ServerVariables["HTTP_X_FORWARDED_FOR"]; } if (string.IsNullOrEmpty(ipStr)) { ipStr = thisValue.ServerVariables["REMOTE_ADDR"]; } if (string.IsNullOrEmpty(ipStr)) { ipStr = thisValue.UserHostAddress; } if (!string.IsNullOrEmpty(ipStr)) { int n = ipStr.IndexOf(','); if (n > -1) { ipStr = n > 0 ? ipStr.Substring(0, n) : null; } } if (IPAddressHelper.IsLoopback(ipStr)) { IPAddress ip = IPAddressHelper.GetLocalIP(); if (ip != null) { ipStr = ip.ToString(); } } return(ipStr.ToNullIfEmpty()); }