Esempio n. 1
0
        /// <summary>
        /// Sets logger or exits application.
        /// </summary>
        /// <param name="logFilePath"></param>
        /// <returns>Return logger.</returns>
        private static ILogger SetLogger(string logFilePath)
        {
            DefaultLogger tempDefaultLogger = null;

            try
            {
                tempDefaultLogger = new DefaultLogger(logFilePath);
                tempDefaultLogger.Open(true);
                DefaultLogger defaultLogger = tempDefaultLogger;
                tempDefaultLogger = null;
                return(defaultLogger);
            }
            catch (UnauthorizedAccessException ex)
            {
                throw new UnauthorizedAccessException(@Resources.MessageCannotOpenLogFile, ex);
            }
            catch (DirectoryNotFoundException ex)
            {
                throw new DirectoryNotFoundException(@Resources.MessageCannotOpenLogFile, ex);
            }
            catch (PathTooLongException ex)
            {
                throw new PathTooLongException(@Resources.MessageCannotOpenLogFile, ex);
            }
            catch (IOException ex)
            {
                throw new IOException(@Resources.MessageCannotOpenLogFile, ex);
            }
            catch (ArgumentException ex)
            {
                throw new ArgumentException(@Resources.MessageCannotOpenLogFile, ex);
            }
            catch (SecurityException ex)
            {
                throw new SecurityException(@Resources.MessageCannotOpenLogFile, ex);
            }
            finally
            {
                if (tempDefaultLogger != null)
                {
                    tempDefaultLogger.Dispose();
                }
            }
        }