Пример #1
0
        public void Log_method_should_correctly_convert_levels(LogLevel vostokLevel, SerilogLevel serilogLevel)
        {
            var @event = new LogEvent(vostokLevel, DateTimeOffset.Now, null);

            adapter.Log(@event);

            observedEvent.Level.Should().Be(serilogLevel);
        }
Пример #2
0
        public void Test(Serilog.Events.LogEventLevel serilogLevel, Enyim.LogLevel enyimLevel, string message, Exception exception)
        {
            var mock = new Moq.Mock <ILogEventSink>();
            var root = new LoggerConfiguration()
                       .MinimumLevel.Verbose()
                       .WriteTo.Sink(mock.Object)
                       .CreateLogger();

            Enyim.LogManager.AssignFactory(new Enyim.Diagnostics.SerilogLoggerFactory(root));
            LogManager.Create(typeof(SerilogLoggerAdapterTests)).Log(enyimLevel, exception, message);

            mock.Verify(sink => sink.Emit(It.Is <LogEvent>(e => e.Level == serilogLevel && e.MessageTemplate.Text == message && e.Exception == exception)));
        }
Пример #3
0
        public static void Exception(Exception exception, Serilog.Events.LogEventLevel logEventLevel = LogEventLevel.Error, string exceptionNote = null)
        {
            string LogType         = "SeqException";
            string Message         = null;
            string StackTrace      = null;
            string Source          = null;
            string InnerMessage    = null;
            string InnerStackTrace = null;
            string InnerSource     = null;
            string format          = "{lt}: {Message} {StackTrace} {Source} {InnerMessage} {InnerStackTrace} {InnerSource} {ExceptionNote}";

            Message         = exception.Message;
            StackTrace      = exception?.StackTrace ?? ".";
            Source          = exception?.Source ?? ".";
            InnerMessage    = (exception?.InnerException?.Message) ?? ".";
            InnerStackTrace = (exception?.InnerException?.StackTrace) ?? ".";
            InnerSource     = (exception?.InnerException?.Source) ?? ".";
            Write(logEventLevel, format, LogType, Message, StackTrace, Source, InnerMessage, InnerStackTrace, InnerSource, exceptionNote);
        }
Пример #4
0
        public void Should_copy_primary_simple_components_of_log_events(SerilogLevel serilogLevel, LogLevel vostokLevel)
        {
            var serilogEvent = new SerilogEvent(
                DateTimeOffset.Now,
                serilogLevel,
                new Exception("I have failed.."),
                new MessageTemplate("Hello!", Enumerable.Empty <MessageTemplateToken>()),
                Enumerable.Empty <LogEventProperty>());

            serilogLogger.Write(serilogEvent);

            var vostokEvent = observedEvents.Single();

            vostokEvent.Level.Should().Be(vostokLevel);
            vostokEvent.Timestamp.Should().Be(serilogEvent.Timestamp);
            vostokEvent.MessageTemplate.Should().Be("Hello!");
            vostokEvent.Exception.Should().BeSameAs(serilogEvent.Exception);
            vostokEvent.Properties.Should().BeEmpty();
        }
        /// <summary>
        /// Transcode's all videos of a site
        /// </summary>
        /// <param name="configuration">Json configuration of IDBrowserService as IDBrowserConfiguration class</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <param name="siteName">Site name to transcode</param>
        /// <param name="videoSize">Video size to transcode. (e.g. Hd480, Hd720, Hd1080)</param>
        /// <param name="taskCount">FFmpeg task count (Default 2)</param>
        /// <param name="logLevel">Serilog log level</param>
        public static void TranscodeAllVideos(IDBrowserConfiguration configuration, CancellationToken cancellationToken,
                                              string siteName, string videoSize, Serilog.Events.LogEventLevel logLevel, int taskCount)
        {
            LoggingLevelSwitch loggingLevelSwitch = new LoggingLevelSwitch
            {
                MinimumLevel = logLevel
            };

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.ControlledBy(loggingLevelSwitch)
                         .WriteTo.File(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log", "ConsoleFunctions.log"))
                         .CreateLogger();

            SiteSettings siteSettings = configuration.Sites[siteName];

            IDImagerDB db = new IDImagerDB(GetIDImagerDBOptionsBuilder <IDImagerDB>(siteSettings.ConnectionStrings.DBType,
                                                                                    siteSettings.ConnectionStrings.IDImager).Options);

            var query = db.idCatalogItem
                        .Include(x => x.idFilePath)
                        .Where(x => configuration.VideoFileExtensions.Contains(x.idFileType));

            ProgressTaskFactory progressTaskFactory = new ProgressTaskFactory(taskCount, 100, 60, Log.Logger);

            Task windowChangeListenerTask = new Task(() =>
            {
                int width  = Console.WindowWidth;
                int height = Console.WindowHeight;

                while (!cancellationToken.IsCancellationRequested)
                {
                    if (width != Console.WindowWidth || height != Console.WindowHeight)
                    {
                        width  = Console.WindowWidth;
                        height = Console.WindowHeight;

                        progressTaskFactory.RedrawConsoleWindows(100, 60);
                    }

                    cancellationToken.WaitHandle.WaitOne(100);
                }
            }, cancellationToken);

            windowChangeListenerTask.Start();

            if (!IsWindows)
            {
                // Log output scrolling not supported at the moment because Console.MoveBufferArea is currently not supported under Linux and MacOs.
                // But we can write a single infoline.
                progressTaskFactory.WriteLog("Log output in console not supported under Linux at the moment. Please take a look at the ConsoleFunctions.log in Logs directory.",
                                             true, LogEventLevel.Information);
            }

            List <TranscodeVideoBatchInfo> listTranscodeVideoBatch = new List <TranscodeVideoBatchInfo>();

            foreach (idCatalogItem catalogItem in query)
            {
                catalogItem.GetHeightAndWidth(out int originalVideoWidth, out int originalVideoHeight);

                string strTranscodeFilePath = StaticFunctions.GetTranscodeFilePath(catalogItem.GUID,
                                                                                   siteSettings.ServiceSettings.TranscodeDirectory, videoSize);
                FileInfo transcodeFileInfo = new FileInfo(strTranscodeFilePath);

                if (!transcodeFileInfo.Exists)
                {
                    string strOriginalFilePath = StaticFunctions.GetImageFilePath(catalogItem, siteSettings.ServiceSettings.FilePathReplace);

                    TranscodeVideoBatchInfo transcodeVideoBatchInfo = new TranscodeVideoBatchInfo(catalogItem.GUID, originalVideoWidth, originalVideoHeight,
                                                                                                  strOriginalFilePath, strTranscodeFilePath);

                    listTranscodeVideoBatch.Add(transcodeVideoBatchInfo);
                }
            }

            db.Dispose();

            int intTotalCount = listTranscodeVideoBatch.Count();
            int intCounter    = 1;
            TranscodeVideoBatchInfo lastTranscodeVideoBatch = listTranscodeVideoBatch.LastOrDefault();

            foreach (TranscodeVideoBatchInfo transcodeVideoBatchInfo in listTranscodeVideoBatch)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                string strTranscodeFilePath = StaticFunctions.GetTranscodeFilePath(transcodeVideoBatchInfo.GUID,
                                                                                   siteSettings.ServiceSettings.TranscodeDirectory, videoSize);

                StaticFunctions.GetTranscodeVideoSize(videoSize, transcodeVideoBatchInfo.VideoWidth, transcodeVideoBatchInfo.VideoHeight,
                                                      out VideoSize targetVideoSize, out int targetVideoWidth, out int targetVideoHeight);

                var conversionOptions = StaticFunctions.GetConversionOptions(targetVideoSize, transcodeVideoBatchInfo.VideoWidth,
                                                                             transcodeVideoBatchInfo.VideoHeight);

                progressTaskFactory.WriteLog(string.Format("Transcoding file {0} of {1} with guid {2} and path \"{3}\" from resolution {4}x{5} to {6}x{7} ",
                                                           intCounter, intTotalCount, transcodeVideoBatchInfo.GUID, transcodeVideoBatchInfo.VideoFileInfo.FullName, transcodeVideoBatchInfo.VideoWidth,
                                                           transcodeVideoBatchInfo.VideoHeight, targetVideoWidth, targetVideoHeight),
                                             IsWindows, LogEventLevel.Information);

                ProgressTask progressTask = progressTaskFactory.GetIdleProgressTask();

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                if (progressTask == null)
                {
                    progressTask = progressTaskFactory
                                   .WaitForAnyTask()
                                   .Result;
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                string progressBarText = string.Format("{0} ({1} of {2})", transcodeVideoBatchInfo.TranscodeFileInfo.Name, intCounter, intTotalCount);

                progressTask.Task = new Task(() => {
                    TranscodeVideoProgressTask(transcodeVideoBatchInfo, videoSize, cancellationToken, progressTask, progressBarText);
                });

                progressTask.Task.Start();

                // If we are on the last item we have to wait for all tasks to complete
                if (transcodeVideoBatchInfo == lastTranscodeVideoBatch)
                {
                    progressTaskFactory.WaitForAllTasks();
                }

                intCounter++;
            }

            Log.CloseAndFlush();
        }
Пример #6
0
 public LoggingLevelSpecification(Serilog.Events.LogEventLevel levelToMeet)
 {
     _levelToMeet = levelToMeet;
 }
Пример #7
0
 public bool IsSatisifedBy(Serilog.Events.LogEventLevel level)
 {
     return(level >= _levelToMeet);
 }
Пример #8
0
        public static void Exception(string exceptionMessage, Serilog.Events.LogEventLevel logEventLevel = LogEventLevel.Error)
        {
            var format = exceptionMessage;

            Write(logEventLevel, format);
        }
        public static void Handle(string[] args)
        {
            IDBrowserConfiguration configuration = new IDBrowserConfiguration();

            Configuration.Bind(configuration);

            if (args[0] == nameof(ConsoleFunctions.TranscodeAllVideos))
            {
                if (args.Count() < 3)
                {
                    Console.WriteLine("Please specify the site name, video size (e.g. Hd480, Hd720, Hd1080), number of FFmpeg instances (optional, default 2, max 12) and log level (optional, default Error, possible values Verbose, Debug, Information, Warning, Error and Fatal) to transcode videos.");
                }
                else
                {
                    string strSiteName  = args[1];
                    string strVideoSize = args[2];
                    int    taskCount    = 2;
                    Serilog.Events.LogEventLevel logLevel = LogEventLevel.Error;

                    if (args.Count() > 3)
                    {
                        taskCount = Math.Min(12, Math.Max(1, int.Parse(args[3])));
                    }

                    if (args.Count() > 4)
                    {
                        logLevel = (LogEventLevel)Enum.Parse(typeof(LogEventLevel), args[4], true);
                    }

                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

                    Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) =>
                    {
                        cancellationTokenSource.Cancel();
                        e.Cancel = true;
                    };

                    ConsoleFunctions.TranscodeAllVideos(configuration, cancellationTokenSource.Token, strSiteName,
                                                        strVideoSize, logLevel, taskCount);
                    Console.WriteLine("Transcoding complete");
                }
            }
            else if (args[0] == nameof(ConsoleFunctions.GenerateThumbnails))
            {
                if (args.Count() < 2)
                {
                    Console.WriteLine("Please specify the site name");
                }
                else
                {
                    string strSiteName = args[1];

                    Console.WriteLine("Please enter optional from datetime: ");
                    DateTime.TryParse(Console.ReadLine(), out DateTime fromDateTime);

                    Console.WriteLine("Please enter optional to datetime: ");
                    DateTime.TryParse(Console.ReadLine(), out DateTime toDateTime);

                    Console.WriteLine("Please enter optional file filter: ");
                    string strFileFilter = Console.ReadLine();

                    Console.WriteLine("Please enter optional image guid: ");
                    string strImageGuid = Console.ReadLine();

                    Console.WriteLine("Please enter 'true' when thumbnails should be overwritten: ");
                    bool.TryParse(Console.ReadLine(), out bool overwrite);

                    Console.WriteLine("Generating thumbnails...");
                    ConsoleFunctions.GenerateThumbnails(configuration, strSiteName, fromDateTime,
                                                        toDateTime, strFileFilter, strImageGuid, overwrite);
                }
            }
            else
            {
                Console.WriteLine("Command not recognized. Possible Commands:");
                Console.WriteLine("TranscodeAllVideos");
            }
        }