-
-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 (MigrationTools): centralize log path creation and improve logging
Refactor log path creation into a dedicated LogLocationService to centralize and simplify log path management. This change ensures consistent log path generation and usage across the application. Additionally, enhance logging by including log path information in log messages and enabling file size limits and rolling intervals for log files. This improves log management and helps in diagnosing issues by providing clear log locations.
- Loading branch information
Showing
4 changed files
with
55 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace MigrationTools.Services | ||
{ | ||
public class LogLocationService | ||
{ | ||
private static string logDate = DateTime.Now.ToString("yyyyMMddHHmmss"); | ||
|
||
|
||
private static string _logsPath = CreateLogsPath(); | ||
|
||
public static string GetLogPath() | ||
{ | ||
// Check if the string has been generated. | ||
if (_logsPath == null) | ||
{ | ||
// Generate the string at runtime (e.g., any custom logic). | ||
_logsPath = CreateLogsPath(); | ||
} | ||
|
||
// Return the _logsPath string. | ||
return _logsPath; | ||
} | ||
|
||
private static string CreateLogsPath() | ||
{ | ||
string exportPath; | ||
string assPath = Assembly.GetEntryAssembly().Location; | ||
exportPath = Path.Combine(Path.GetDirectoryName(assPath), "logs", logDate); | ||
if (!Directory.Exists(exportPath)) | ||
{ | ||
Directory.CreateDirectory(exportPath); | ||
} | ||
|
||
return exportPath; | ||
} | ||
} | ||
} |