File tree Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -360,4 +360,7 @@ MigrationBackup/
360
360
.ionide /
361
361
362
362
# Fody - auto-generated XML schema
363
- FodyWeavers.xsd
363
+ FodyWeavers.xsd
364
+
365
+ # ## Project-specific
366
+ Builds /**
Original file line number Diff line number Diff line change 3
3
public static class Log
4
4
{
5
5
private static string ServerName = "Minecraft Server" ;
6
-
6
+ public static StreamWriter ? LogFile ;
7
7
public static void Server ( string message )
8
8
{
9
9
string FormattedMsg = $ "[SRV][{ ServerName } ] { message } ";
@@ -14,18 +14,21 @@ public static void Info(string message)
14
14
{
15
15
string FormattedMsg = $ "[INF][{ ServerName } ] { message } ";
16
16
Console . WriteLine ( FormattedMsg ) ;
17
+ if ( LogFile != null ) { LogFile . WriteLine ( FormattedMsg ) ; }
17
18
Handlers ? . Invoke ( FormattedMsg ) ;
18
19
}
19
20
public static void Warn ( string message )
20
21
{
21
22
string FormattedMsg = $ "[WRN][{ ServerName } ] { message } ";
22
23
Console . WriteLine ( FormattedMsg ) ;
24
+ if ( LogFile != null ) { LogFile . WriteLine ( FormattedMsg ) ; }
23
25
Handlers ? . Invoke ( FormattedMsg ) ;
24
26
}
25
27
public static void Error ( string message )
26
28
{
27
29
string FormattedMsg = $ "[ERR][{ ServerName } ] { message } ";
28
30
Console . WriteLine ( FormattedMsg ) ;
31
+ if ( LogFile != null ) { LogFile . WriteLine ( FormattedMsg ) ; }
29
32
Handlers ? . Invoke ( FormattedMsg ) ;
30
33
}
31
34
Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ public class SMSM : BackgroundService
15
15
private readonly ILogger < SMSM > Logger ;
16
16
private readonly IHostApplicationLifetime Lifetime ;
17
17
18
- public SMSM ( ILogger < SMSM > logger , IHostApplicationLifetime lifetime )
18
+ public SMSM ( ILogger < SMSM > logger , IHostApplicationLifetime lifetime ) // TODO: Get the logger to output to the Windows event log, and redirect output there.
19
19
{
20
+ Log . Info ( "SMSM initializing" ) ;
20
21
this . Logger = logger ;
21
22
this . Lifetime = lifetime ;
22
23
this . Lifetime . ApplicationStopping . Register ( Stop ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,15 @@ public static async Task Main(string[] args)
6
6
{
7
7
if ( args . Length != 1 ) { Console . WriteLine ( "Please specify the config file path as command-line argument." ) ; Environment . Exit ( - 3 ) ; }
8
8
SMSM . ConfigFile = args [ 0 ] ;
9
+
10
+ string LogDate = DateTime . Now . ToString ( "yyyy-MM-dd\\ _HH-mm-ss" ) ;
11
+ try { Log . LogFile = new StreamWriter ( File . Create ( $ "C:\\ Games\\ Minecraft\\ LTS\\ SMSMLog-{ LogDate } .txt") ) { AutoFlush = true } ; }
12
+ catch ( Exception Exc )
13
+ {
14
+ Log . Error ( "Could not create log file." ) ;
15
+ Log . Error ( Exc . ToString ( ) ) ;
16
+ }
17
+
9
18
//Console.TreatControlCAsInput = true;
10
19
11
20
IHost host = Host . CreateDefaultBuilder ( args )
You can’t perform that action at this time.
0 commit comments