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.
66 lines
2.7 KiB
66 lines
2.7 KiB
using Microsoft.AspNetCore;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
using Serilog.Sinks.InfluxDB;
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace StudyCenter
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
Console.OutputEncoding = Encoding.UTF8;
|
|
var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json", optional: true)
|
|
.Build();
|
|
WebHost.CreateDefaultBuilder(args)
|
|
.ConfigureAppConfiguration((c, o) =>
|
|
{
|
|
if (config.GetValue<bool>("useConfigServer", false))
|
|
{
|
|
o.AddNacosConfiguration(o =>
|
|
{
|
|
var section = config.GetSection("nacosConfigServer");
|
|
o.ServerAddresses = section.GetValue<string>("ServerAddresses").Split(';').ToList();
|
|
o.Optional = section.GetValue<bool>("Optional");
|
|
o.DataId = section.GetValue<string>("DataId");
|
|
o.Group = section.GetValue<string>("Group");
|
|
o.Tenant = section.GetValue<string>("Tenant");
|
|
});
|
|
}
|
|
})
|
|
.ConfigureLogging((c, o) => //http://localhost:9200/_search?size=100
|
|
{
|
|
if (config.GetValue("useLogServer", false))
|
|
{
|
|
var url = c.Configuration["elasticsearch:url"];
|
|
var connectionInfo = new InfluxDBConnectionInfo
|
|
{
|
|
Address = config["logserver:influxdb:address"],
|
|
Port = config.GetValue("logserver:influxdb:port", 8086),
|
|
DbName = config["logserver:influxdb:dbName"],
|
|
Username = config["logserver:influxdb:username"],
|
|
Password = config["logserver:influxdb:password"]
|
|
};
|
|
Log.Logger = new LoggerConfiguration().WriteTo.InfluxDB("iotcenter", connectionInfo).CreateLogger();
|
|
}
|
|
else
|
|
{
|
|
Log.Logger = new LoggerConfiguration().WriteTo.Console().CreateLogger();
|
|
}
|
|
o.AddSerilog();
|
|
Log.Logger.Information("start...");
|
|
})
|
|
.UseStartup<Startup>()
|
|
.Build()
|
|
.Run();
|
|
}
|
|
}
|
|
} |