예제 #1
0
 /// <summary>
 /// Logs a status based message and a list, to the console and to a <see cref="LogFile"> if one is found.
 /// </summary>
 /// <param name="status">The status to print to the console and <see cref="LogFile">.</param>
 /// <param name="message">The message to print to the console and <see cref="LogFile">.</param>
 /// <param name="output">The list to print to the console and <see cref="LogFile">.</param>
 public void Log(int status, string message, List <string> output)
 {
     LoggerBase.Log(_sender, status, message, output, _debug, _logFilePath);
 }
예제 #2
0
 /// <summary>
 /// Logs a status-based message to the console and the <see cref="LogFile"> if one is found.
 /// </summary>
 /// <param name="status">The status to output.</param>
 /// <param name="message">The message to output.</param>
 public void Log(int status, string message)
 {
     LoggerBase.Log(_sender, status, message, _debug, _logFilePath);
 }
예제 #3
0
 /// <summary>
 /// Logs a blank to the console, but not the <see cref="LogFile">.
 /// </summary>
 public void Log()
 {
     LoggerBase.Log();
 }
예제 #4
0
 /// <summary>
 /// Logs a message to the console, but not the <see cref="LogFile">.
 /// </summary>
 /// <param name="message">The message to print to the console.</param>
 public void Log(string message)
 {
     LoggerBase.Log(message);
 }
예제 #5
0
        /// <summary>
        /// Creates a new log file.
        /// </summary>
        /// <param name="path">The path of the new log file.</param>
        public LogFile(string path)
        {
            try
            {
                if (Path.GetFileName(path) == "" || Path.GetFullPath(path) == null)
                {
                    //Use default naming convention.
                    dateTime = DateTime.Now.ToString("[HH-mm-ss tt]dd-MM-yyyy");
                    logFilePath += $@"{path}\\{dateTime}.log";
                }
                else
                {
                    //Use custom naming convention and uniary file.
                    if (path.EndsWith(".log"))
                    {
                        logFilePath = path;
                    }
                    else
                    {
                        logFilePath = $@"{path}.log";
                    }
                }

                var dirName = Path.GetDirectoryName(logFilePath);
                DirectoryInfo d = new DirectoryInfo(dirName);
                if (!(d.Exists))
                {
                    if (Logger.GetDebug())
                        LoggerBase.LogInfo(GetType().Name, "Creating LogFile Directory...");
                    d.Create();
                    if (Logger.GetDebug())
                        LoggerBase.LogInfo(GetType().Name, "LogFile Directory Created Successfully.");
                    var fileName = Path.GetFileName(logFilePath);
                    FileInfo f = new FileInfo(fileName);
                    if (!(f.Exists))
                    {
                        if (Logger.GetDebug())
                            LoggerBase.LogInfo(GetType().Name, "Creating LogFile...");
                        f.Create();
                        if (Logger.GetDebug())
                            LoggerBase.LogInfo(GetType().Name, "LogFile Created Successfully.");
                    }

                }
                else
                {
                    var fileName = Path.GetFileName(logFilePath);
                    FileInfo f = new FileInfo(fileName);
                    if (!(f.Exists))
                    {
                        if (Logger.GetDebug())
                            LoggerBase.LogInfo(GetType().Name, "Creating LogFile...");
                        f.Create();
                        if (Logger.GetDebug())
                            LoggerBase.LogInfo(GetType().Name, "LogFile Created Successfully.");
                    }
                }
            }
            catch (Exception ex)
            {
                if (Logger.GetDebug())
                    LoggerBase.LogError(GetType().Name, "Unknown Exception", ex.ToString());
            }
        }