Exemplo n.º 1
0
        private long GetMaxFileSize()
        {
            long result = 10 * 1024 * 2014; // default is 10 MBytes.

            if (AttributesCopy.ContainsKey(MaxFileSizeKey))
            {
                if (long.TryParse(AttributesCopy[MaxFileSizeKey], out result))
                {
                    if (result > max)
                    {
                        result = max;
                    }
                    else
                    {
                        result *= 1024 * 1024; // expressed in MB!
                        if (result > max)
                        {
                            result = max;
                        }
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private string GetApplicationName()
        {
            if (AttributesCopy.ContainsKey(ApplicationName))
            {
                return(AttributesCopy[ApplicationName]);
            }

            return(String.Empty);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get the number of days we will keep the files in the directory.
        /// </summary>
        /// <returns>The number from the config. Default is 10.</returns>
        private int GetRetentionDays()
        {
            var result = 10; // default is 10 days.

            if (AttributesCopy.ContainsKey(MaxFileDaysKey))
            {
                int.TryParse(AttributesCopy[MaxFileDaysKey], out result);
            }

            return(result);
        }
Exemplo n.º 4
0
        private TimeSpan GetFrequency()
        {
            TimeSpan result = TimeSpan.FromSeconds(10); // default is 10 seconds.

            if (AttributesCopy.ContainsKey(FrequencyKey))
            {
                TimeSpan.TryParse(AttributesCopy[FrequencyKey], out result);
                if (TimeSpan.Zero == result)
                {
                    result = TimeSpan.FromSeconds(10);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// return the directory given in the config fileand if nothing is mentionned, the CommonApplicationData folder is used.
        /// </summary>
        /// <returns>The <see cref="String"/> directory.</returns>
        private String GetLogDirectory()
        {
            var pathDoesntExist = false;

            if (AttributesCopy.ContainsKey(DirectoryPathKey))
            {
                if (IO.Path.IsRelative(AttributesCopy[DirectoryPathKey]))
                {
                    try
                    {
                        return(IO.Path.MakeFullPath(AppDomain.CurrentDomain.BaseDirectory, AttributesCopy[DirectoryPathKey]));
                    }
                    catch
                    {
                        pathDoesntExist = true;
                    }
                }
                else
                {
                    try
                    {
                        if (Directory.Exists(AttributesCopy[DirectoryPathKey]))
                        {
                            return(AttributesCopy[DirectoryPathKey]);
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        pathDoesntExist = true;
                    }
                }
            }

            if (pathDoesntExist)
            {
                LogMessage($"The path for the log file does not exist: {AttributesCopy[DirectoryPathKey]}.");
            }
            // null path => no backup of messages.
            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// return the directory given in the config fileand if nothing is mentionned, the CommonApplicationData folder is used.
        /// </summary>
        /// <returns>The <see cref="String"/> directory.</returns>
        private String GetLogDirectory()
        {
            var pathDoesntExist = false;

            if (AttributesCopy.ContainsKey(DirectoryPathKey))
            {
                if (IO.Path.IsRelative(AttributesCopy[DirectoryPathKey]))
                {
                    try
                    {
                        return(IO.Path.MakeFullPath(AppDomain.CurrentDomain.BaseDirectory, AttributesCopy[DirectoryPathKey]));
                    }
                    catch
                    {
                        pathDoesntExist = true;
                    }
                }
                else
                {
                    try
                    {
                        if (Directory.Exists(AttributesCopy[DirectoryPathKey]))
                        {
                            return(AttributesCopy[DirectoryPathKey]);
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        pathDoesntExist = true;
                    }
                }
            }

            if (pathDoesntExist)
            {
                LogMessage($"The path for the log file does not exist: {AttributesCopy[DirectoryPathKey]}.");
            }

            return(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
        }