public IActionResult Index()
        {
            QueueProcessor.ProcessQueue(".\\My\\Queue").Wait();


            return(View());
        }
Пример #2
0
        private static void Main(string[] args)
        {
            // Configure NLog.
            var nlogConfig = new LoggingConfiguration();

            var fileTarget = new FileTarget("file")
            {
                FileName         = "nlog.log",
                KeepFileOpen     = true,
                ConcurrentWrites = false
            };

            nlogConfig.AddTarget(fileTarget);
            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));

            var consoleTarget = new ConsoleTarget("console");

            nlogConfig.AddTarget(consoleTarget);
            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));



            // Configure PostSharp Logging to use NLog.
            LoggingServices.DefaultBackend = new NLogLoggingBackend(new LogFactory(nlogConfig));

            LogManager.EnableLogging();



            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
Пример #3
0
        private static void Main(string[] args)
        {
            try
            {
                // Initialize Loupe.
                Log.StartSession();

                // Configure PostSharp Logging to use Loupe.
                LoggingServices.DefaultBackend = new LoupeLoggingBackend();

                // Simulate some business logic.
                QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");

                Console.WriteLine("Press Enter to finish.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                //Optional but recommended - write fatal exceptions to loupe this way so the session is marked as crashed.
                Log.RecordException(ex, "Program", false);
                throw;
            }
            finally
            {
                // Close Loupe.
                Log.EndSession();
            }
        }
Пример #4
0
        private static void Main(string[] args)
        {
            // Configure PostSharp Logging to output logs to the console.
            LoggingServices.DefaultBackend = new ConsoleLoggingBackend();

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
Пример #5
0
        private static void Main(string[] args)
        {
            // Configure Common.Logging to direct outputs to the system console.
            LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();

            // Configure PostSharp Logging to direct outputs to Common.Logging.
            LoggingServices.DefaultBackend = new CommonLoggingLoggingBackend();

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
Пример #6
0
        private static void Main(string[] args)
        {
            // Configure Log4Net
            XmlConfigurator.Configure(new FileInfo("log4net.config"));

            // Configure PostSharp Logging to use Log4Net
            var log4NetLoggingBackend = new Log4NetLoggingBackend();

            LoggingServices.DefaultBackend = log4NetLoggingBackend;

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
Пример #7
0
        private static void Main(string[] args)
        {
            // Configure Serilog.
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.File("serilog.log")
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            // Configure PostSharp Logging to use Serilog
            LoggingServices.DefaultBackend = new SerilogLoggingBackend();

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
Пример #8
0
        private static void Main(string[] args)
        {
            // Test that LoggingCircuitBreaker works
            TestMethodThrowingException();
            TestMethodThrowingException();
            if (testMethodCounter != 1)
            {
                Console.Error.WriteLine("LoggingCircuitBreaker aspect does not work.");
                return;
            }
            LoggingCircuitBreaker.Reset();

            // Configure NLog.
            var nlogConfig = new LoggingConfiguration();

            var fileTarget = new FileTarget("file")
            {
                FileName         = "nlog.log",
                KeepFileOpen     = true,
                ConcurrentWrites = false
            };

            nlogConfig.AddTarget(fileTarget);
            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));

            var consoleTarget = new ConsoleTarget("console");

            nlogConfig.AddTarget(consoleTarget);
            nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget));

            LogManager.Configuration = nlogConfig;
            LogManager.EnableLogging();

            TextLoggingBackend backend = new CircuitBreakingLoggingBackend();

            LoggingServices.DefaultBackend = backend;

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");

            // Simulate an error.
            LoggingCircuitBreaker.Break();
            Console.WriteLine("*** ERROR ***   There should be no log lines below.");

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
Пример #9
0
        private static void Main(string[] args)
        {
            // The output template must include {Indent} for nice output.
            const string template = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Indent:l}{Message}{NewLine}{Exception}";

            // Configure a Serilog logger.
            var logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.File("serilog.log", outputTemplate: template)
                         .WriteTo.ColoredConsole(outputTemplate: template)
                         .CreateLogger();

            // Configure PostSharp Logging to use Serilog
            LoggingServices.DefaultBackend = new SerilogLoggingBackend(logger);

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
        }
Пример #10
0
        private static void Main(string[] args)
        {
            // Register the custom logging backend.
            var backend = new CustomLoggingBackend();

            LoggingServices.DefaultBackend = backend;

            // Register the custom parameter formatter.
            LoggingServices.Formatters.Register(new FancyIntFormatter());


            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");

            ExampleFormattable.Greet(new ExampleFormattable {
                FirstName = "Yuri", LastName = "Gagarin"
            });
        }
Пример #11
0
        private static void Main(string[] args)
        {
            var eventSourceBackend = new EventSourceLoggingBackend(new PostSharpEventSource());

            if (eventSourceBackend.EventSource.ConstructionException != null)
            {
                throw eventSourceBackend.EventSource.ConstructionException;
            }

            LoggingServices.DefaultBackend = eventSourceBackend;

            // Simulate some business logic.
            QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");

            // To collect and view the log:
            //   1. Download PerfView from https://www.microsoft.com/en-us/download/details.aspx?id=28567.
            //   2. Execute: perfview.exe collect -OnlyProviders *PostSharp-Patterns-Diagnostics
            //   3. Execute this program.
            //   4. In PerfView, click 'Stop collecting', then in the PerfView tree view click 'PerfViewData.etl.zip' and finally 'Events'.
        }
Пример #12
0
        static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", optional: false)
                                .Build();

            var courseService = new CourseService(
                privateKeyPath: configuration.GetSection("PrivateKeyPath").Value,
                emailToImpersonate: configuration.GetSection("AdminEmail").Value,
                scopes: new string[] { Scope.ClassroomCourses, Scope.ClassroomProfileEmails, Scope.ClassroomRosters }
                );

            Parser.Default.ParseArguments <AddStudentOptions,
                                           ExecuteCommandListOptions>
                (args)
            .WithParsed <AddStudentOptions>(opts =>
            {
                var addStudentToCourseCommand = new AddStudentToCourseCommand(
                    courseService: courseService,
                    courseId: opts.CourseId,
                    studentEmail: opts.Email
                    );

                addStudentToCourseCommand.Execute();
            })
            .WithParsed <ExecuteCommandListOptions>(opts =>
            {
                var logger = new Logger();
                var queue  = new QueueProcessor(logger);

                var textToCommandParser = new TextToCommandParser(courseService, logger);

                using (var reader = new StreamReader(opts.Path))
                {
                    string line;

                    while ((line = reader.ReadLine()) != null)
                    {
                        var command = textToCommandParser.Parse(line);
                        var node    = new Node(command);

                        if (node.Command.CommandType == CommandType.AddStudent)
                        {
                            var queueLastNode = queue.Queue.Last();
                            queueLastNode.Children.Add(node);
                        }
                        else
                        {
                            queue.Enqueue(node);
                        }
                    }
                }

                queue.ProcessQueue();

                if (queue.HasAnyNodeFailed && opts.Reprocess)
                {
                    queue.ReprocessFailedQueue();
                }
            })
            .WithNotParsed(errors =>
            {
                foreach (var error in errors)
                {
                    Console.WriteLine(error.ToString());
                }
            });
        }
        public async Task ProcessQueueAtLeastOneAttemptMadeToReceiveMessage()
        {
            await _queueProcessor.ProcessQueue(A.Fake <ILambdaContext>());

            A.CallTo(() => _sqsClient.ReceiveMessageAsync(A <ReceiveMessageRequest> ._, A <CancellationToken> ._)).MustHaveHappened(Repeated.Exactly.Once);
        }