//Alternative log to emphasize the username public static void Log(string user, string msg) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); string logUser = "******" + user + " --------------"; ReadWriteFiles.WriteToFile(Model.logFileName, logUser); string logTime = "[" + thisDay + "]" + " " + msg; ReadWriteFiles.WriteToFile(Model.logFileName, logTime); }
/**------------------HELPER FUNCTION-------------------*/ //Handler adding new account to the database private void addNewAccount() { foreach (string key in accounts.Keys) { if (String.Equals(key, this.userLb.Text)) { Logger.Log("This user already had password"); return; } } //Add the username with this password to the Dictionary accounts accounts.Add(this.userLb.Text, this.passwordTxtBox.Text); //Write the password with this username to the data file string msg = Model.UserName + "," + Model.Password + "," + Model.KeyWord; ReadWriteFiles.WriteToFile(pathFileToSave, msg); Logger.Log("User [" + Model.UserName + "] - password [" + Model.Password + "] - keyword [" + Model.KeyWord + "] has been added to the file at [" + this.pathFileToSave + "]"); Logger.Log("Completed [" + whatPurpose + "] form"); this.lockButton = true; }
//Main log function with 5 levels public static void Log(string msg, int isNewLine = 0) { string logTime = null; if (isNewLine == 0) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "[" + thisDay + "]" + " " + msg; } else if (isNewLine == 1) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "\n[" + thisDay + "]" + " " + msg; } else if (isNewLine == 2) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "\n---------[" + msg + "]---------"; } else if (isNewLine == 3) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "-----------------------" + "\n-----------------------\n[" + thisDay + "]" + " " + msg; } else if (isNewLine == 4) { string thisDay = DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"); logTime = "\n\n=====================================================================\n" + "=====================================================================\n" + "==================NEW SECTION [" + thisDay + "]=================\n" + "=====================================================================\n" + "=====================================================================\n"; } ReadWriteFiles.WriteToFile(Model.logFileName, logTime); }