/
Program.cs
51 lines (41 loc) · 1.25 KB
/
Program.cs
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
using NLog;
using NLog.Config;
using NLog.Targets;
namespace Nagase;
public static class Program
{
static async Task Main()
{
InitNLog();
var logger = LogManager.GetCurrentClassLogger();
if (Config.Instance.DebugMode)
{
logger.Debug($"{Config.EnvDebugMode} has been set to true.");
}
if (string.IsNullOrEmpty(Config.Instance.OpenAIApiKey))
{
logger.Fatal($"{Config.EnvOpenAIApiKey} not set, the program will now terminate.");
Environment.Exit(1);
}
if (string.IsNullOrEmpty(Config.Instance.TelegramBotApiToken))
{
logger.Fatal($"{Config.EnvTelegramBotApiToken} not set, the program will now terminate.");
Environment.Exit(1);
}
Bot.Instance.Start();
}
static void InitNLog()
{
var config = new LoggingConfiguration();
var consoleTarget = new ConsoleTarget("chatgpt-telegram-bot");
if (Config.Instance.DebugMode)
{
config.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleTarget);
}
else
{
config.AddRule(LogLevel.Info, LogLevel.Fatal, consoleTarget);
}
LogManager.Configuration = config;
}
}