using Infrastructure.Application; using Infrastructure.Configuration; using Infrastructure.Extensions; using Infrastructure.Web.Hosting; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Serilog; using Serilog.Formatting.Json; using Serilog.Sinks.Elasticsearch; using Serilog.Sinks.RollingFile; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace IoTCenter { public class Program { public static void Main(string[] args) { var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true) .Build(); WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration(o => o.AddNacosConfiguration(o => { var section = config.GetSection("nacos"); o.ServerAddresses = section.GetValue("ServerAddresses").Split(';').ToList(); o.Optional = section.GetValue("Optional"); o.DataId = section.GetValue("DataId"); o.Group = section.GetValue("Group"); o.Tenant = section.GetValue("Tenant"); })) //.Configure(o => //{ // o.UseNacosAspNetCore(); //}) //.ConfigureServices((c, o) => //{ // o.AddNacosAspNetCore(c.Configuration); //}) .ConfigureLogging((c, o) => //http://localhost:9200/_search?size=100 { var url = c.Configuration["elasticsearch:url"]; Log.Logger = new LoggerConfiguration() .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(url)) { TypeName = "_doc", AutoRegisterTemplate = true, AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7, FailureCallback = e => Console.WriteLine("Unable to submit event " + e.MessageTemplate), EmitEventFailure = EmitEventFailureHandling.WriteToSelfLog | EmitEventFailureHandling.WriteToFailureSink | EmitEventFailureHandling.RaiseCallback, FailureSink = new RollingFileSink("logs/log.txt", new JsonFormatter(), fileSizeLimitBytes: 100 * 1024 * 1024, 1) }) .CreateLogger(); o.AddSerilog(); }) .UseStartup() .Build() .Run(); } private static void NewMethod(string[] args) { Console.OutputEncoding = Encoding.UTF8; var host = "localhost"; var macAddress = Helper.Instance.GetMacAddress(); var webHost = WebHost.CreateDefaultBuilder(args) .Config(new List { new EFConfigurationValue { Id = "sn", Value=macAddress }, new EFConfigurationValue { Id = "id", Value= macAddress.Md5() }, new EFConfigurationValue { Id = "code", Value= "根据id生成的授权码" }, new EFConfigurationValue { Id = "usercenter:key", Value= "123456"}, new EFConfigurationValue { Id = "usercenter:login", Value= $"http://{host}:8010/Account/Login"}, new EFConfigurationValue { Id = "usercenter:logout", Value= $"http://{host}:8010/Account/Logout"}, new EFConfigurationValue { Id = "usercenter:register", Value= $"http://{host}:8010/Account/Register"}, new EFConfigurationValue { Id = "influxdb:url", Value= $"http://{host}:8086"}, new EFConfigurationValue { Id = "influxdb:usr", Value= "admin"}, new EFConfigurationValue { Id = "influxdb:pwd", Value= "admin"}, new EFConfigurationValue { Id = "srs", Value= "http://localhost:1985"}, // new EFConfigurationValue { Id = "name", Value= "物联中心"}, new EFConfigurationValue { Id = "logo", Value= "/images/logo.png",Type= InputType.ImageUrl}, new EFConfigurationValue { Id = "copyright", Value= "Copyright © {now} Company. All rights reserved",Type= InputType.Html}, // new EFConfigurationValue { Id = "server.urls", Value= "http://*:8013" }, new EFConfigurationValue { Id = "BasePath", Value= "/IoTCenter"}, new EFConfigurationValue { Id = "security:key", Value= "111111111111111111111111"}, new EFConfigurationValue { Id = "jwt:key", Value= "111111111111111111111111"}, new EFConfigurationValue { Id = "jwt:issuer", Value= "111111111111111111111111"}, new EFConfigurationValue { Id = "jwt:audience", Value= "111111111111111111111111"}, new EFConfigurationValue { Id = "openapi.name", Value= "v1" }, new EFConfigurationValue { Id = "openapi.title", Value= "web api" }, new EFConfigurationValue { Id = "openapi.version", Value= "1.0" }, }, useLogServer: true) .Build(); var logger = webHost.Services.GetRequiredService>(); try { webHost.Run(); } catch (Exception ex) { logger.LogError(ex.ToString()); } } } }