Beispiel #1
0
        static void Main(string[] args)
        {
            ILogger logger = new QuickLoggerNative(".\\");

            try
            {
                System.Console.WriteLine(LoggerEventTypes.LOG_ALL.ToString());

                DeleteDemoFiles();

                ILoggerProvider myFileDemoProvider    = CreateFileDemoProvider(FILELOGPATH);
                ILoggerProvider myConsoleDemoProvider = CreateConsoleDemoProvider();
                AssignProviderCallbacks(myFileDemoProvider);
                AssignProviderCallbacks(myConsoleDemoProvider);

                //Create new config instance, ADD Providers and Write to disk.
                ILoggerConfigManager configManager = new QuickLoggerFileConfigManager(CONFIGPATH);
                if (File.Exists(CONFIGPATH))
                {
                    configManager.Load();
                }
                else
                {
                    //Add providers to settings
                    configManager.GetSettings().addProvider(myFileDemoProvider);
                    configManager.GetSettings().addProvider(myConsoleDemoProvider);
                    //Write settings to disk
                    configManager.Write();
                }

                //Create a new instance of NativeQuickLogger
                configManager.GetSettings().Providers().ForEach(x => logger.AddProvider(x));

                System.Console.WriteLine(logger.GetLoggerNameAndVersion());

                // Main!
                logger.Info("QuickLogger demo program main loop started.");

                for (int x = 0; x < 100; x++)
                {
                    logger.Info("Info");
                    for (int y = 0; y < 100; y++)
                    {
                        logger.Error("Error");
                        for (int z = 0; z < 100; z++)
                        {
                            logger.Custom("Custom");
                        }
                    }
                }

                logger.Info("QuickLogger demo program finished.");
                System.Console.ReadKey();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message + " " + logger.GetLastError());
                System.Console.ReadKey();
            }
        }
        public void Add_Logger_Default_Console_Provider_To_New_Logger()
        {
            ILogger logger = new QuickLoggerNative(".\\");
            ILoggerProviderProps providerProps = new QuickLoggerProviderProps("Test Console Provider", "ConsoleProvider");

            providerProps.SetProviderInfo(_consoleProviderInfo);
            ILoggerProvider loggerProvider = new QuickLoggerProvider(providerProps);

            logger.AddProvider(loggerProvider);
            logger.Info("Works");
            logger.Custom("Works");
            logger.Error("Works");
            logger.Success("Works");
            logger.RemoveProvider(loggerProvider);
        }
        public void Add_Logger_Default_Redis_Provider_To_New_Logger()
        {
            ILogger logger = new QuickLoggerNative(".\\");
            ILoggerProviderProps providerProps = new QuickLoggerProviderProps("Test Redis (ELK) Provider", "RedisProvider");

            providerProps.SetProviderInfo(_fileProviderInfo);
            ILoggerProvider loggerProvider = new QuickLoggerProvider(providerProps);

            logger.AddProvider(loggerProvider);
            logger.Info("Info line");
            logger.Custom("Custom line");
            logger.Error("Error line");
            logger.Success("Succes line");
            Assert.That(FindStringInsideFile(_configPath, "Info line"), Is.True);
            Assert.That(FindStringInsideFile(_configPath, "Custom line"), Is.True);
            Assert.That(FindStringInsideFile(_configPath, "Error line"), Is.True);
            Assert.That(FindStringInsideFile(_configPath, "Success line"), Is.True);
            logger.RemoveProvider(loggerProvider);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            ILogger logger = new QuickLoggerNative("");

            try
            {
                System.Console.WriteLine(LoggerEventTypes.LOG_ALL.ToString());

                DeleteDemoFiles();

                ILoggerProvider myFileDemoProvider    = CreateFileDemoProvider(FILELOGPATH);
                ILoggerProvider myConsoleDemoProvider = CreateConsoleDemoProvider();
                ILoggerProvider myRedisProvider       = CreateRedisProvider();

                /* Optional config handler
                 * Create new config instance, ADD Providers and Write to disk.
                 * ILoggerConfigManager configManager = new QuickLoggerFileConfigManager(CONFIGPATH);
                 * if (File.Exists(CONFIGPATH)) { configManager.Load(); }
                 * else
                 * {
                 *  //Add providers to settings
                 *  configManager.GetSettings().addProvider(myFileDemoProvider);
                 *  configManager.GetSettings().addProvider(myConsoleDemoProvider);
                 *  //Write settings to disk
                 *  configManager.Write();
                 * }*/

                QuickLoggerSettings quickLoggerSettings = new QuickLoggerSettings();


                quickLoggerSettings.Providers().Add(myConsoleDemoProvider);
                quickLoggerSettings.Providers().Add(myFileDemoProvider);
                quickLoggerSettings.Providers().Add(myRedisProvider);

                quickLoggerSettings.Providers().ForEach(x =>
                {
                    logger.AddProvider(x);
                    AssignProviderCallbacks(x);
                });

                System.Console.WriteLine(logger.GetLoggerNameAndVersion());
                //logger.TestCallbacks();

                // Main!
                logger.Info("QuickLogger demo program main loop started.");

                for (int x = 1; x <= 100; x++)
                {
                    logger.Info("QuickLogger demo program main loop iteration. Nº " + x.ToString());
                    logger.Success("QuickLogger demo program main loop iteration. Nº " + x.ToString());
                    logger.Trace("QuickLogger demo program main loop iteration. Nº " + x.ToString());
                    logger.Warning("QuickLogger demo program main loop iteration. Nº " + x.ToString());
                    logger.Error("QuickLogger demo program main loop iteration. Nº " + x.ToString());
                    logger.Debug("QuickLogger demo program main loop iteration. Nº " + x.ToString());
                }

                logger.Info("QuickLogger demo program finished.");
                System.Console.ReadKey();

                quickLoggerSettings.Providers().ForEach(x =>
                {
                    // We remove providers we created before (code sanity)
                    logger.DisableProvider(x);
                    logger.RemoveProvider(x);
                });
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message + " " + logger.GetLastError());
                System.Console.ReadKey();
            }
        }