예제 #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();
                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();
            }
        }