forked from gnsilence/HangfireHttpJob
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (53 loc) · 1.96 KB
/
Program.cs
File metadata and controls
58 lines (53 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using CommonUtils;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.WindowsServices;
using Microsoft.Extensions.Logging;
namespace JobsServer
{
public class Program
{
public static void Main(string[] args)
{
//如果是控制台下使用,后面加上console参数即可,默认是服务方式
var isService = !(Debugger.IsAttached || args.Contains("--console"));
if (isService)
{
//获取当前程序所在目录
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
Directory.SetCurrentDirectory(pathToContentRoot);
}
var builder = CreateWebHostBuilder(
args.Where(arg => arg != "--console").ToArray());
var host = builder.Build();
if (isService)
{
// To run the app without the CustomWebHostService change the
// next line to host.RunAsService();
host.RunAsService();
}
else
{
host.Run();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseUrls(HangfireSettings.Instance.UseApollo?ConfigSettings.Instance.ServiceAddress:HangfireSettings.Instance.ServiceAddress)//启用配置的地址
.ConfigureLogging((hostingContext, logging) =>
{
//logging.AddEventLog();//启用系统事件日志,
})
.ConfigureAppConfiguration((context, config) =>
{
// Configure the app here.
}).UseStartup<Startup>();
}
}
}