private void LogMessage(FileLogInfo fileLogInfo) { string logMessage = string.Empty; // [ HOW THE MESSAGE SHOULD BE PRESENTED ] switch (fileLogInfo.Presentation) { case Presentation.FULL_DETAIL: logMessage = MessageLogUtility.GenerateFullLogDetail(fileLogInfo, source, eventID); break; case Presentation.LOG_WITH_SEVERITY: logMessage = MessageLogUtility.GenerateLogWithSeverity(fileLogInfo, false); break; case Presentation.LOG__ONLY: logMessage = MessageLogUtility.GenerateLogOnly(fileLogInfo, isException: false); break; case Presentation.CUSTOM: logMessage = fileLogInfo.LogMessage.Trim(); break; } string pathTillDrive = FileUtils.CheckOrCreateLogDirectory(fileLogInfo); WriteToFile(fileLogInfo, logMessage, pathTillDrive, appendLine: true); //// [ HOW THE MESSAGE SHOULD BE INSERTED ] ------- WORK OUT HERE >> //switch (fileLogInfo.InsertionType) //{ // case InsertionType.Append: // WriteToFile(fileLogInfo, logMessage, pathTillDrive, appendLine: true); // break; // case InsertionType.NewFile: // WriteToFile(fileLogInfo, logMessage, pathTillDrive, appendLine: true); // break; //} }
internal static string GenerateLogWithSeverity(FileLogInfo fileLogInfo, bool isException) { StringBuilder message = new StringBuilder(); message.Append(Environment.NewLine); if (fileLogInfo.EnableDate) { message.Append("[" + DateTime.Now.ToString(fileLogInfo.LogDateFormat).Trim() + "]" + Environment.NewLine); message.Append(FileUtils.Default_LineBreaker + Environment.NewLine); } message.Append(FileUtils.HEADER_SEVERITY + fileLogInfo.LogLevel.ToString() + Environment.NewLine); if (isException) { message.Append(FileUtils.HEADER_EXCEPTION_MSG + fileLogInfo.Exception.Message.Trim() + Environment.NewLine); if (!string.IsNullOrEmpty(fileLogInfo.LogMessage)) { message.Append(FileUtils.HEADER_Message_General + fileLogInfo.LogMessage.Trim() + Environment.NewLine); } } else { message.Append(FileUtils.HEADER_Message + fileLogInfo.LogMessage.Trim() + Environment.NewLine); } return(message.ToString()); }
internal static string GenerateFullLogDetail(FileLogInfo fileLogInfo, string source, string eventID) { StringBuilder message = new StringBuilder(); message.Append(Environment.NewLine); if (fileLogInfo.EnableDate) { message.Append("[" + DateTime.Now.ToString(fileLogInfo.LogDateFormat).Trim() + "]" + Environment.NewLine); message.Append(FileUtils.Default_LineBreaker + Environment.NewLine); } message.AppendLine(FileUtils.HEADER_APP_UP_TIME + (DateTime.Now - Process.GetCurrentProcess().StartTime).ToString()); if (!string.IsNullOrEmpty(source)) { message.Append(FileUtils.HEADER_SOURCE + source + Environment.NewLine); } if (!string.IsNullOrEmpty(eventID)) { message.Append(FileUtils.HEADER_EVENT_ID + eventID + Environment.NewLine); } message.Append(FileUtils.HEADER_SEVERITY + fileLogInfo.LogLevel.ToString() + Environment.NewLine); message.Append(FileUtils.HEADER_Message + fileLogInfo.LogMessage.Trim() + Environment.NewLine); if (!string.IsNullOrEmpty(fileLogInfo.ErrorCode)) { message.Append(FileUtils.HEADER_Error_Code + fileLogInfo.ErrorCode.Trim() + Environment.NewLine); } return(message.ToString()); }
public void Send(FileLogInfo file) { var bucketName = this.bucket ?? file.Bucket; if (string.IsNullOrEmpty(bucketName)) { return; } var contentType = Atoms.MimeType.GetMimeType(file.ContentType); var contentEncoding = file.ContentEncoding; var obj = new Google.Apis.Storage.v1.Data.Object { Name = file.FileName, ContentType = contentType, ContentEncoding = contentEncoding, Bucket = bucketName, }; if (dry) { Console.WriteLine($"DRY: push {file.FileName}"); var sReader = new StreamReader(file.Content); var content = sReader.ReadToEnd(); Console.WriteLine(content); } else { client.UploadObject(obj, file.Content, this.opts, progress); } }
public DynamixDefaultController() { if (EnableDevelopmentLog) { fileLogInfo = DefaultFileLogInfo(); logInfo = new FileLogger <FileLogInfo>(); } }
private void InstantiateDefaultLogInfo() { // YOU CAN CREATE YOUR OWN FileLogInfo // I AM USING A DEFAULT LOG INFO FROM THE LIBRARY HERE // NOTE : THE FILE LOGGER IS CONFIGURED TO AUTO CHOOSE A // DRIVE WITH MINIMUM 5 GB OF SPACE FOR LOGGING THE DATA fileLogInfo = DynamixDefaultController.DefaultFileLogInfo(); }
private void WriteLog(FileLogInfo fileLogInfo) { switch (fileLogInfo.LogType) { case LogType.Exception: LogException(fileLogInfo); break; default: LogMessage(fileLogInfo); break; } }
/// <summary> /// Instantiate your Log Info Type Here /// You can even create your own File Log Info class as per your need /// </summary> /// <returns></returns> public static FileLogInfo DefaultFileLogInfo() { FileLogInfo fileLogInfo = new FileLogInfo(); fileLogInfo.FilePath = FilePaths.ChooseADrive(FileUtils.SpaceLimit, true).Name; fileLogInfo.DedicatedFolder = true; fileLogInfo.FolderName = Execution_LogFolderName; fileLogInfo.FileName = GenerateLogFileName(); fileLogInfo.Presentation = Presentation.FULL_DETAIL; return(fileLogInfo); }
public BasicSamples() { logInfo = new FileLogger <FileLogInfo>(); fileLogInfo = new FileLogInfo(); fileLogInfo.FilePath = FilePaths.ChooseADrive(FileUtils.SpaceLimit, true).Name; fileLogInfo.DedicatedFolder = true; fileLogInfo.FolderName = "YOUR-CUSTOM-FOLDER-NAME"; // <---- Optional fileLogInfo.FileName = "YOUR-CUSTOM-FILE-NAME.log"; // <---- Optional fileLogInfo.Presentation = Presentation.FULL_DETAIL; }
private void btnBasicLogging_Click(object sender, EventArgs e) { FileLogInfo logInfo = new FileLogInfo(); logInfo.LogMessage = "Just a basic file logging"; FileLogger <FileLogInfo> fileLogger = new FileLogger <FileLogInfo>(); fileLogger.Write(logInfo); lblMessage.Text = $"Message logged to the root of the application due to no configuration at {logInfo.FilePath}"; }
internal static string GenerateFullLogDetail_EX(FileLogInfo fileLogInfo, string source, string eventID) { StringBuilder message = new StringBuilder(); message.Append(Environment.NewLine); if (fileLogInfo.EnableDate) { message.Append("[" + DateTime.Now.ToString(fileLogInfo.LogDateFormat).Trim() + "]" + Environment.NewLine); message.Append(FileUtils.Default_LineBreaker + Environment.NewLine); } message.AppendLine(FileUtils.HEADER_APP_UP_TIME + (DateTime.Now - Process.GetCurrentProcess().StartTime).ToString()); if (!string.IsNullOrEmpty(source)) { message.Append(FileUtils.HEADER_SOURCE + source + Environment.NewLine); } if (!string.IsNullOrEmpty(eventID)) { message.Append(FileUtils.HEADER_EVENT_ID + eventID + Environment.NewLine); } if (fileLogInfo.Exception.Data.Count > 0) { var statusCode = fileLogInfo.Exception.Data.Keys.Cast <string>().First(); // ERROR CODE var statusMessage = fileLogInfo.Exception.Data[statusCode]; // MESSAGE message.Append("Status Code: " + statusCode + Environment.NewLine); message.Append("Status Message: " + statusMessage + Environment.NewLine); } message.Append(FileUtils.HEADER_SEVERITY + fileLogInfo.LogLevel.ToString() + Environment.NewLine); message.Append(FileUtils.HEADER_EXCEPTION_CLASS); message.Append(GetExceptionTypeStack(fileLogInfo.Exception)); message.AppendLine(string.Empty); message.Append(FileUtils.HEADER_EXCEPTION_MSG); message.Append(GetExceptionMessageStack(fileLogInfo.Exception)); message.AppendLine(string.Empty); message.Append(GetExceptionCallStack(fileLogInfo.Exception)); if (!string.IsNullOrEmpty(fileLogInfo.LogMessage)) { message.Append(FileUtils.HEADER_Message_General + fileLogInfo.LogMessage.Trim() + Environment.NewLine); } return(message.ToString()); }
private void Export(string fullPath, Dictionary <string, string> options) { FileLogInfo fli = null; try { using (fli = new FileLogInfo(options, File.OpenRead(fullPath))) { backend.Send(fli); } } finally { File.Delete(fullPath); } }
public static void StandardLogging() { FileLogInfo fileLogInfo = new FileLogInfo(); fileLogInfo.FilePath = FilePaths.ChooseADrive(FileUtils.SpaceLimit, true).Name; fileLogInfo.DedicatedFolder = true; // <---- Optional fileLogInfo.FolderName = "Your-Folder-Name"; // <---- Optional fileLogInfo.FileName = "Your-File-Name"; // <---- Optional fileLogInfo.Presentation = Presentation.FULL_DETAIL; ILogStrategy <FileLogInfo> logInfo = new FileLogger <FileLogInfo>(); LogEngine.LogMessage(logInfo, fileLogInfo, "Your-Message"); // OR LogEngine.LogMessage(logInfo, fileLogInfo, new Exception("Your-Exception")); }
public static string CheckOrCreateLogDirectory(FileLogInfo fileLogInfo) { if (fileLogInfo.DedicatedFolder) { string fullPath = Path.Combine(fileLogInfo.FilePath, fileLogInfo.FolderName); if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } return(fullPath); } else { return(fileLogInfo.FilePath); } }
private void WriteToFile(FileLogInfo fileLogInfo, string message, string path, bool appendLine) { if (string.IsNullOrEmpty(fileLogInfo.FileName)) { fileLogInfo.FileName = FileUtils.Default_Log_Name; } string fileName = FileUtils.GenerateFileName(fileLogInfo); string fullPath = Path.Combine(path, fileName); using (StreamWriter writer = new StreamWriter(fullPath, appendLine)) { writer.WriteLine(message); writer.Close(); } }
public static void ValidateLogFileDefaults(FileLogInfo fileLogInfo) { fileLogInfo.FileName.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.FILE_NAME_MISSING); fileLogInfo.FilePath.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.FILE_PATH_MISSING); if (fileLogInfo.LogType == LogType.Message) { fileLogInfo.LogMessage.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.FILE_LOG_MESSAGE_MISSING); } else { if (fileLogInfo.Exception == null) { throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.FILE_LOG_EXCEPTION_MISSING); } } }
public ILogMessage Write(T logInfo) { try { if (logInfo == null) { throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.NULL_LOG_INFO); } if (typeof(T) != typeof(FileLogInfo)) { throw ErrorGenerator.Generate(ErrorCode.CDX_FILE_CAST_FAIL); } FileLogInfo fileLogInfo = logInfo as FileLogInfo; FileUtils.ValidateLogFileDefaults(fileLogInfo); if (fileLogInfo.EnableDate && string.IsNullOrEmpty(fileLogInfo.LogDateFormat)) { fileLogInfo.LogDateFormat = FileUtils.Default_Date_Format; } if (fileLogInfo.DedicatedFolder && string.IsNullOrEmpty(fileLogInfo.FolderName)) { fileLogInfo.FolderName = FileUtils.Default_Log_FolderName; } // [ WRITE LOG TO FILE ] WriteLog(fileLogInfo); fileLogInfo.LogMessage = string.Empty; return(new LogMessageCode() { Status = StatusType.SUCCESS, Message = Messages.LOG_SUCCESSFULL }); } catch (Exception ex) { return(new LogMessageCode() { Status = StatusType.EXCEPTION, Message = ex.Message }); } }
/// <summary> /// Generate A file name based on the provided information /// </summary> /// <param name="fileLogInfo"></param> /// <returns></returns> public static string GenerateFileName(FileLogInfo fileLogInfo) { string extension = Path.GetExtension(fileLogInfo.FileName); if (extension.Trim() == string.Empty) { extension = FileUtils.Default_File_Ext; } string fileName = Path.GetFileNameWithoutExtension(fileLogInfo.FileName); if (fileLogInfo.InsertionType == InsertionType.NewFile) { fileName += "-" + DateTime.Now.Date.ToString(Default_File_DateAppendor); } fileName += extension; return(fileName); }
private void LogException(FileLogInfo fileLogInfo) { string logMessage = string.Empty; switch (fileLogInfo.Presentation) { case Presentation.FULL_DETAIL: logMessage = MessageLogUtility.GenerateFullLogDetail_EX(fileLogInfo, source, eventID); break; case Presentation.LOG_WITH_SEVERITY: logMessage = MessageLogUtility.GenerateLogWithSeverity(fileLogInfo, true); break; case Presentation.LOG__ONLY: default: logMessage = MessageLogUtility.GenerateLogOnly(fileLogInfo, isException: true); break; case Presentation.CUSTOM: break; } string pathTillDrive = FileUtils.CheckOrCreateLogDirectory(fileLogInfo); WriteToFile(fileLogInfo, logMessage, pathTillDrive, appendLine: true); }
internal static string GenerateLogOnly(FileLogInfo fileLogInfo, bool isException) { StringBuilder message = new StringBuilder(); message.Append(Environment.NewLine); if (fileLogInfo.EnableDate) { message.Append("[" + DateTime.Now.ToString(fileLogInfo.LogDateFormat).Trim() + "]" + Environment.NewLine); message.Append(FileUtils.Default_LineBreaker + Environment.NewLine); } if (isException) { message.Append(FileUtils.HEADER_Message + fileLogInfo.Exception.Message.Trim() + Environment.NewLine); } else { message.Append(FileUtils.HEADER_Message + fileLogInfo.LogMessage.Trim() + Environment.NewLine); } return(message.ToString()); }