public void AppendFileFactoryCanOpenFileMultipleTimes()
        {
            string fileName = GetFileName();
            string actual = String.Empty;
            string expected = String.Empty;

            PrepareEmptyFile(fileName);

            AppendFileFactory fileFactory = new AppendFileFactory(fileName);

            using (StreamWriter f = fileFactory.GetOuputFile())
            {
                f.WriteLine(testText);
            }

            using (StreamWriter f = fileFactory.GetOuputFile())
            {
                f.WriteLine(testText);
            }

            expected = testText + Environment.NewLine + testText + Environment.NewLine;
            actual = File.ReadAllText(fileName);

            Assert.AreEqual(expected, actual);
        }
        public void AppendFileFactoryCanCreateNewFile()
        {
            string fileName = GetFileName();
            string fileText = String.Empty;

            DeleteFile(fileName);

            AppendFileFactory fileFactory = new AppendFileFactory(fileName);

            using (StreamWriter f = fileFactory.GetOuputFile())
            {
                f.WriteLine(string.Empty);
            }

            Assert.IsTrue(File.Exists(fileName));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Configuration example
        /// </summary>
        static public void Configure()
        {
            string    connectionString;
            string    fullFileName;
            JobLogger jl = JobLogger.Instance;

            connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];

            fullFileName = System.Configuration.ConfigurationManager.AppSettings["LogFileDirectory"]
                           + "LogFile"
                           + DateTime.Now.ToShortDateString()
                           + ".txt";

            IDatabase database = new SQLDatabase(connectionString);

            IFileFactory fileFactory = new AppendFileFactory(fullFileName);

            Dictionary <Type, int> messageCodes = new Dictionary <Type, int> {
                { typeof(GeneralMessage), 1 },
                { typeof(WarningMessage), 2 },
                { typeof(ErrorMessage), 3 }
            };

            Dictionary <Type, ConsoleColor> messageColors = new Dictionary <Type, ConsoleColor>
            {
                { typeof(GeneralMessage), ConsoleColor.Blue },
                { typeof(WarningMessage), ConsoleColor.Yellow },
                { typeof(ErrorMessage), ConsoleColor.Red }
            };

            jl
            .Reset()
            .SetLoggers(new List <ILogger>
            {
                new ConsoleLogger(messageColors),
                new TextFileLogger(fileFactory),
                new SQLDBLogger(database, messageCodes)
            })
            .AcceptMessages <GeneralMessage>()
            .AcceptMessages <WarningMessage>()
            .AcceptMessages <ErrorMessage>();

            jl.LogMessage(new ErrorMessage("This is an error message"));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Configuration example 
        /// </summary>
        public static void Configure()
        {
            string connectionString;
            string fullFileName;
            JobLogger jl = JobLogger.Instance;

            connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];

            fullFileName = System.Configuration.ConfigurationManager.AppSettings["LogFileDirectory"]
                + "LogFile"
                + DateTime.Now.ToShortDateString()
                + ".txt";

            IDatabase database = new SQLDatabase(connectionString);

            IFileFactory fileFactory = new AppendFileFactory(fullFileName);

            Dictionary<Type, int> messageCodes = new Dictionary<Type, int> {
                { typeof(GeneralMessage), 1},
                { typeof(WarningMessage), 2},
                { typeof(ErrorMessage), 3}
            };

            Dictionary<Type, ConsoleColor> messageColors = new Dictionary<Type, ConsoleColor>
            {
                {typeof(GeneralMessage), ConsoleColor.Blue},
                {typeof(WarningMessage), ConsoleColor.Yellow},
                {typeof(ErrorMessage), ConsoleColor.Red}
            };

            jl
               .Reset()
               .SetLoggers(new List<ILogger>
                {
                    new ConsoleLogger(messageColors),
                    new TextFileLogger(fileFactory),
                    new SQLDBLogger(database, messageCodes)
                })
               .AcceptMessages<GeneralMessage>()
               .AcceptMessages<WarningMessage>()
               .AcceptMessages<ErrorMessage>();

            jl.LogMessage(new ErrorMessage("This is an error message"));
        }
 public void AppendFileFictoryCannotBeCreatedWithAllSpacesFileName()
 {
     IFileFactory fileFactory = new AppendFileFactory("    ");
 }
 public void AppendFileFictoryCannotBeCreatedWithNullFileName()
 {
     IFileFactory fileFactory = new AppendFileFactory(null);
 }