-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclsLog.cs
More file actions
45 lines (39 loc) · 1.33 KB
/
clsLog.cs
File metadata and controls
45 lines (39 loc) · 1.33 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
using System;
using System.IO;
namespace MyDatabaseBackupService
{
internal class clsLog
{
// Log a message to a file with a timestamp
//The service logs all its state transitions (Start, Stop, Pause, Continue, Shutdown) to a file named ServiceStateLog.txt in the configured directory.
// Each log entry includes a timestamp for tracking purposes.
public static void LogServiceEvent(string message)
{
string logMessage = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}\n";
File.AppendAllText(clsGlobal.logFilePath, logMessage);
// Write to console if running interactively
if (Environment.UserInteractive)
{
Console.WriteLine(logMessage);
}
}
public static bool CreateFolderIfDoesNotExist(string FolderPath)
{
// Check if the folder exists
if (!Directory.Exists(FolderPath))
{
try
{
// If it doesn't exist, create the folder
Directory.CreateDirectory(FolderPath);
return true;
}
catch (Exception ex)
{
return false;
}
}
return true;
}
}
}