using Serilog; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using Serilog.Sinks.RollingFile; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.DependencyInjection; using solarApp.Service; using Microsoft.Extensions.Logging; namespace solarApp { static class Program { /// /// The main entry point for the application. /// log ref: https://www.thecodebuzz.com/file-logging-in-windows-form-application-using-serilog/ /// [STAThread] static void Main() { // Application.SetHighDpiMode(HighDpiMode.SystemAware); // Application.EnableVisualStyles(); // Application.SetCompatibleTextRenderingDefault(false); // ///Generate Host Builder and Register the Services for DI // var builder = new HostBuilder() // .ConfigureServices((hostContext, services) => // { // services.AddScoped(); // services.AddScoped(); // //services.AddScoped(); // //services.AddSingleton(); ////Add Serilog //var serilogLogger = new LoggerConfiguration() // .WriteTo.File("app_log.txt") // .CreateLogger(); // services.AddLogging(x => // { // x.SetMinimumLevel(LogLevel.Information); // x.AddSerilog(logger: serilogLogger, dispose: true); // }); // }); // var host = builder.Build(); // using (var serviceScope = host.Services.CreateScope()) // { // var services = serviceScope.ServiceProvider; // try // { // var form1 = services.GetRequiredService(); // Application.Run(form1); // Console.WriteLine("Success"); // } // catch (Exception ex) // { // Console.WriteLine("Error Occured"); // } // } Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() // 設定最低顯示層級 預設: Information .WriteTo.File("Logs/solarApp/log-.log", rollingInterval: RollingInterval.Day, // 每天一個檔案 outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u5}] {Message:lj}{NewLine}{Exception}" ) // 輸出到檔案 檔名範例: log-20211005.log .CreateLogger(); Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new fmExcel()); Application.Run(new fmArchive()); //Application.Run(new fmTest()); //Application.Run(new fmMain()); Log.CloseAndFlush(); } } }