private void LogBeforeReadingFromProvider(DateTime requestTime, int userId) { string msg = "[1]--Start reading image from source.".PadRight(84) + " Request by UserId: " + userId.GetFormattedUserId() + " , at " + DateTimeFormatter.ConvertTimeToCompactString(requestTime, true); _logger?.LogCacheStat(msg, userId); }
private void LogReadOldImageFromCache(int userId) { string statusMessage = "From cache . OLD IMAGE until cache is updated" + " , LastUpdate: " + DateTimeFormatter.ConvertTimeToCompactString(GetLastCacheAccess(userId), true) //(_lastCacheAccess, true) // + " Request by UserId: " + userId.GetFormattedUserId(); _logger?.LogCacheStat(statusMessage, userId); }
private static (string strPrevTime, string strRequestTime) GetLogDateTimeValuesAsStrings( DateTime lastUpdate, DateTime requestTime) { string strPrevTime = DateTimeFormatter.ConvertTimeToCompactString(lastUpdate, true); string strRequestTime = DateTimeFormatter.ConvertTimeToCompactString(requestTime, true); return(strPrevTime, strRequestTime); }
private void LogAfterReadingFromProvider(int userId) { string msg = "[2]--Finish reading image from source. " + " " + "Request by UserId: " + userId.GetFormattedUserId() + " , at " + DateTimeFormatter.ConvertTimeToCompactString(GetLastCacheAccess(userId), true); _logger?.LogCacheStat(msg, userId); }
private string CreateMessageWhenCanReturnImage() { string statusMessage = ("From cache (2)." + // Granted access to cache "Current = userId: " + _cacheUpdateService.UserId.GetFormattedUserId()).PadRight(50) + "LastUpdate: " + DateTimeFormatter.ConvertTimeToCompactString(_cacheUpdateService.LastUpdate, true); return(statusMessage.PadRight(85)); }
private void LogCanReturnCachedImage(int userId, DateTime timeRequested, bool canReturnImage) { string statusMessage = canReturnImage ? CreateMessageWhenCanReturnImage() : CreateMessageWhenCanNotReturnImage(userId, timeRequested); statusMessage += "Request by userId: " + userId.GetFormattedUserId() + " , at " + DateTimeFormatter.ConvertTimeToCompactString(timeRequested, true); _logger?.LogCacheStat(statusMessage, userId); }
private string PrepareUpdateCacheLogMessage(int newUserId, DateTime lastCacheUpdate) { var statMessage = "UPDATE cache . "; string action = _cacheUpdateService.UserId == newUserId ? "Updated " : "Replaced"; statMessage += $"{action}= userId: " + _cacheUpdateService.UserId.GetFormattedUserId(); statMessage = statMessage.PadRight(50); statMessage += "LastUpdate: " + DateTimeFormatter.ConvertTimeToCompactString(lastCacheUpdate, true) + " "; return(statMessage); }
private void LogNewImageReadFromCache(int userId, DateTime requestTime) { string msg = "From cache (3) = Read image.".PadRight(50) + "LastUpdate: " + DateTimeFormatter.ConvertTimeToCompactString(_imageFromCacheService.CacheLastUpdate, true) + ". Request by UserId: " + userId.GetFormattedUserId() + " lastCacheAccess " + DateTimeFormatter.ConvertTimeToCompactString(GetLastCacheAccess(userId), true) + " => " + DateTimeFormatter.ConvertTimeToCompactString(requestTime, true); _logger?.LogCacheStat(msg, userId); }
private void LogRequestAccessToCache(int userId, DateTime timeRequested, DateTime lastCacheUpdate, int waitTimeMilliSec, string reason) { var requestDelay = (int)timeRequested.Subtract(lastCacheUpdate).TotalMilliseconds; string msg = "From cache (1) = Request access and WAIT".PadRight(50) + "LastUpdate: " + DateTimeFormatter.ConvertTimeToCompactString(lastCacheUpdate, true) + $" Request by userId: {userId.GetFormattedUserId()} " + " at " + DateTimeFormatter.ConvertTimeToCompactString(timeRequested, true) + $" Delta T = {requestDelay} ms." + $" Time to wait = {waitTimeMilliSec} ms {reason}"; _logger?.LogCacheStat(msg, userId); }
public static void WriteImageToFile(Image image, DateTime dateTime, string imageDirectory, IMiniLogger logger, int userId, string userIp, bool roundSecondsToZero = true) { if (image == null) { return; } if (string.IsNullOrWhiteSpace(imageDirectory)) { return; } dateTime = RoundSecondsToZero(dateTime, roundSecondsToZero); string dateTimeCompact = DateTimeFormatter.ConvertTimeToCompactString(dateTime: dateTime, withMilliSeconds: false); WriteImageToFile(image, imageDirectory, dateTimeCompact, logger, userId, userIp); }
private static void WriteToLogFile(string fileName, string text) { if (string.IsNullOrEmpty(fileName)) { return; } if (string.IsNullOrEmpty(text)) { return; } string logFileName = GetTodaysLogFileName(fileName); try { lock (LockFileWrite) { DateTime dateTimeNow = _dateTimeProvider.DateTimeNow; string strDateTime = DateTimeFormatter.ConvertTimeToCompactString(dateTime: dateTimeNow, withMilliSeconds: true); text = strDateTime + "," + text; File.AppendAllText(logFileName, text + Environment.NewLine); } } catch (DirectoryNotFoundException) { string directoryName = Path.GetDirectoryName(logFileName); if (!string.IsNullOrWhiteSpace(directoryName)) { Directory.CreateDirectory(directoryName); File.AppendAllText(logFileName, text + Environment.NewLine); } } catch (Exception e) { Console.WriteLine(e); throw; } }
private void LogCacheHasBeenUpdated(string statMessage) { statMessage += " With = userId: " + _cacheUpdateService.UserId.GetFormattedUserId() + " , LastUpdate: " + DateTimeFormatter.ConvertTimeToCompactString(_cacheUpdateService.LastUpdate, true) + " "; _logger?.LogCacheStat(statMessage, _cacheUpdateService.UserId); }