Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Jan 22, 2024
1 parent 5d7a620 commit cbd89f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Rdmp.Core/Logging/DataLoadInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void LogFatalError(string errorSource, string errorDescription)
if (UserSettings.LogToFileSystem && !string.IsNullOrWhiteSpace(UserSettings.FileSystemLogLocation))
{
var logger = FileSystemLogger.Instance;
logger.LogEventToFile("FatalEror", [errorSource,errorDescription, statusID, ID]);
logger.LogEventToFile(FileSystemLogger.AvailableLoggers.FatalError, [errorSource,errorDescription, statusID, ID]);
}
else
{
Expand Down Expand Up @@ -334,7 +334,7 @@ public void LogProgress(ProgressEventType pevent, string Source, string Descript
if (UserSettings.LogToFileSystem && !string.IsNullOrWhiteSpace(UserSettings.FileSystemLogLocation))
{
var logger = FileSystemLogger.Instance;
logger.LogEventToFile("ProgressLog", [ID, pevent, Source, Description]);
logger.LogEventToFile(FileSystemLogger.AvailableLoggers.ProgressLog, [ID, pevent, Source, Description]);
}
else
{
Expand Down
15 changes: 11 additions & 4 deletions Rdmp.Core/Logging/FileSystemLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,31 @@ public class FileSystemLogger
public static FileSystemLogger Instance { get { return lazy.Value; } }


public enum AvailableLoggers
{
ProgressLog,
DataSource,
FatalError
}



private FileSystemLogger()
{
var location = UserSettings.FileSystemLogLocation;
var config = new NLog.Config.LoggingConfiguration();
string[] logs = { "ProgressLog", "DataSource", "FatalError" };
string[] logs = System.Enum.GetNames(typeof(AvailableLoggers));
foreach (var log in logs){
using var nLogEntry = new NLog.Targets.FileTarget(log) { FileName = Path.Combine(location, $"{log}.log"), ArchiveAboveSize = UserSettings.LogFileSizeLimit };
config.AddRule(LogLevel.Info, LogLevel.Info, nLogEntry);
}
NLog.LogManager.Configuration = config;
}


public void LogEventToFile(string logType, object[] logItems)
public void LogEventToFile(AvailableLoggers logType, object[] logItems)
{
var logMessage = $"{string.Join("|", Array.ConvertAll(logItems, item => item.ToString()))}";
var Logger = NLog.LogManager.GetLogger(logType);
var Logger = NLog.LogManager.GetLogger(Enum.GetName(typeof(AvailableLoggers), logType));
Logger.Info(logMessage);
}

Expand Down
2 changes: 1 addition & 1 deletion Rdmp.Core/Logging/TableLoadInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private void RecordNewTableLoadInDatabase(DataLoadInfo parent, string destinatio
if (UserSettings.LogToFileSystem && !string.IsNullOrWhiteSpace(UserSettings.FileSystemLogLocation))
{
var logger = FileSystemLogger.Instance;
logger.LogEventToFile("DataSource", [s.Source,_id ,s.UnknownOriginDate ? "" : s.OriginDate]);
logger.LogEventToFile(FileSystemLogger.AvailableLoggers.DataSource, [s.Source,_id ,s.UnknownOriginDate ? "" : s.OriginDate]);
}
else
{
Expand Down

0 comments on commit cbd89f3

Please sign in to comment.