parent
d32f072457
commit
436d8a5d7c
@ -1,67 +1,89 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using PhotoCollector.Data;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PhotoCollector
|
||||
namespace PhotoCollector;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
internal static class Program
|
||||
public static MainForm MainForm;
|
||||
public static IHost WebHost;
|
||||
|
||||
[STAThread]
|
||||
private static void Main()
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
private static void Main()
|
||||
using var mutex = new Mutex(true, Process.GetCurrentProcess().ProcessName, out var result);
|
||||
if (!result)
|
||||
{
|
||||
using var mutex = new Mutex(true, Process.GetCurrentProcess().ProcessName, out var result);
|
||||
if (!result)
|
||||
{
|
||||
MessageBox.Show($"当前程序只允许运行一个实例");
|
||||
return;
|
||||
}
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo.File(Path.Combine(AppContext.BaseDirectory, "logs", "app.log.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Information))
|
||||
.WriteTo.File(Path.Combine(AppContext.BaseDirectory, "logs", "app.err.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Error))
|
||||
.CreateLogger();
|
||||
try
|
||||
{
|
||||
Log.Information("application start");
|
||||
MessageBox.Show($"当前程序只允许运行一个实例");
|
||||
return;
|
||||
}
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo.File(Path.Combine(AppContext.BaseDirectory, "logs", "app.log.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Information))
|
||||
.WriteTo.File(Path.Combine(AppContext.BaseDirectory, "logs", "app.err.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Error))
|
||||
.CreateLogger();
|
||||
try
|
||||
{
|
||||
Log.Information("application start");
|
||||
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
AppDbContext.Init();
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
Application.ThreadException += new ThreadExceptionEventHandler((s, e) =>
|
||||
{
|
||||
Log.Error(e.Exception.ToString());
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
AppDbContext.Init();
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
Application.ThreadException += new ThreadExceptionEventHandler((s, e) =>
|
||||
{
|
||||
Log.Error(e.Exception.ToString());
|
||||
#if DEBUG
|
||||
MessageBox.Show(e.Exception.ToString());
|
||||
MessageBox.Show(e.Exception.ToString());
|
||||
#endif
|
||||
});
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((s, e) =>
|
||||
{
|
||||
Log.Error(e.ExceptionObject.ToString());
|
||||
});
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((s, e) =>
|
||||
{
|
||||
Log.Error(e.ExceptionObject.ToString());
|
||||
#if DEBUG
|
||||
MessageBox.Show(e.ExceptionObject.ToString());
|
||||
MessageBox.Show(e.ExceptionObject.ToString());
|
||||
#endif
|
||||
});
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new MainForm());
|
||||
Log.Information("application exit");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
});
|
||||
ApplicationConfiguration.Initialize();
|
||||
MainForm = new MainForm();
|
||||
Application.Run(MainForm);
|
||||
Log.Information("application exit");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
#if DEBUG
|
||||
MessageBox.Show(ex.Message);
|
||||
MessageBox.Show(ex.Message);
|
||||
#endif
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task WebHostStartAsync()
|
||||
{
|
||||
WebHost = Host.CreateDefaultBuilder()
|
||||
.ConfigureHostConfiguration(configHost =>
|
||||
{
|
||||
configHost.SetBasePath(AppContext.BaseDirectory);
|
||||
})
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.CaptureStartupErrors(true);
|
||||
webBuilder.UseSetting(WebHostDefaults.DetailedErrorsKey, "true");
|
||||
webBuilder.UseContentRoot(AppContext.BaseDirectory);
|
||||
webBuilder.UseStartup<Startup>();
|
||||
webBuilder.UseUrls("http://localhost:8440");
|
||||
})
|
||||
.Build();
|
||||
await WebHost.StartAsync();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue