parent
d32f072457
commit
436d8a5d7c
@ -1,67 +1,89 @@
|
|||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
using PhotoCollector.Data;
|
using PhotoCollector.Data;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Core;
|
using Serilog.Core;
|
||||||
using Serilog.Events;
|
using Serilog.Events;
|
||||||
using System.Diagnostics;
|
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>
|
using var mutex = new Mutex(true, Process.GetCurrentProcess().ProcessName, out var result);
|
||||||
/// The main entry point for the application.
|
if (!result)
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
private static void Main()
|
|
||||||
{
|
{
|
||||||
using var mutex = new Mutex(true, Process.GetCurrentProcess().ProcessName, out var result);
|
MessageBox.Show($"当前程序只允许运行一个实例");
|
||||||
if (!result)
|
return;
|
||||||
{
|
}
|
||||||
MessageBox.Show($"当前程序只允许运行一个实例");
|
Log.Logger = new LoggerConfiguration()
|
||||||
return;
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||||
}
|
.MinimumLevel.Debug()
|
||||||
Log.Logger = new LoggerConfiguration()
|
.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))
|
||||||
.MinimumLevel.Override("Microsoft", 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))
|
||||||
.MinimumLevel.Debug()
|
.CreateLogger();
|
||||||
.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))
|
try
|
||||||
.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();
|
Log.Information("application start");
|
||||||
try
|
|
||||||
{
|
|
||||||
Log.Information("application start");
|
|
||||||
|
|
||||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||||
AppDbContext.Init();
|
AppDbContext.Init();
|
||||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||||
Application.ThreadException += new ThreadExceptionEventHandler((s, e) =>
|
Application.ThreadException += new ThreadExceptionEventHandler((s, e) =>
|
||||||
{
|
{
|
||||||
Log.Error(e.Exception.ToString());
|
Log.Error(e.Exception.ToString());
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
MessageBox.Show(e.Exception.ToString());
|
MessageBox.Show(e.Exception.ToString());
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((s, e) =>
|
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((s, e) =>
|
||||||
{
|
{
|
||||||
Log.Error(e.ExceptionObject.ToString());
|
Log.Error(e.ExceptionObject.ToString());
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
MessageBox.Show(e.ExceptionObject.ToString());
|
MessageBox.Show(e.ExceptionObject.ToString());
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new MainForm());
|
MainForm = new MainForm();
|
||||||
Log.Information("application exit");
|
Application.Run(MainForm);
|
||||||
}
|
Log.Information("application exit");
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
Log.Error(ex.ToString());
|
{
|
||||||
|
Log.Error(ex.ToString());
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show(ex.Message);
|
||||||
#endif
|
#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