SimpleLogger.SimpleLog.SetLogDir C# (CSharp) Method

SetLogDir() public static method

Set new logging directory
public static SetLogDir ( string logDir, bool createIfNotExisting = false ) : Exception
logDir string The logging diretory to set. When passing null or the empty string, the current working directory is used.
createIfNotExisting bool Try to create directory if not existing. Default is false.
return System.Exception
        public static Exception SetLogDir(string logDir, bool createIfNotExisting = false)
        {
            if(string.IsNullOrEmpty(logDir))
                logDir = Directory.GetCurrentDirectory();

            try
            {
                _logDir = new DirectoryInfo(logDir);

                if(!_logDir.Exists)
                {
                    if(createIfNotExisting)
                    {
                        _logDir.Create();
                    }
                    else
                    {
                        throw new DirectoryNotFoundException(string.Format("Directory '{0}' does not exist!", _logDir.FullName));
                    }
                }
            }
            catch(Exception ex)
            {
                return ex;
            }

            return null;
        }