Пример #1
0
        /// <summary>
        /// Uses the system settings.
        /// </summary>
        /// <param name="webHostBuilder">The web host builder.</param>
        /// <param name="logFileName">Name of the log file.</param>
        /// <param name="includeLogEvent">The include log event.</param>
        /// <returns>IWebHostBuilder.</returns>
        /// <autogeneratedoc />
        public static IWebHostBuilder UseSystemSettings(this IWebHostBuilder webHostBuilder, string logFileName,
                                                        Func <LogEvent, bool> includeLogEvent)
        {
            var operatingSystem  = new OperatingSystem();
            var appConfiguration = GetAppConfiguration();
            var fileSystem       = new FileSystem(appConfiguration, operatingSystem);

            var loggerSettings      = new SerilogLoggerSettings(fileSystem, appConfiguration, LoggingOutputFlags.AppFull);
            var loggerConfiguration =
                LoggerConfigurationFactory.CreateLoggerConfiguration(appConfiguration, logFileName, loggerSettings,
                                                                     includeLogEvent);
            var loggerFactory =
                LoggerConfigurationFactory.CreatePureSeriLoggerFactory(loggerSettings, loggerConfiguration);

            webHostBuilder.ConfigureServices(services =>
                                             services.AddSingleton(loggerFactory));

            webHostBuilder.ConfigureServices(services =>
                                             services.AddSingleton <ILoggerFactory>(loggerFactory));

            webHostBuilder.ConfigureServices(services =>
                                             services.AddSingleton <IOperatingSystem>(operatingSystem));

            webHostBuilder.ConfigureServices(services =>
                                             services.AddSingleton <IFileSystem>(fileSystem));

            return(webHostBuilder);
        }
        public void FileSystem_GetCommonApplicationDataFolderPath_Osx()
        {
            var operatingSystem = new OperatingSystem();
            Mock <IOperatingSystem> operatingSystemMock = new Mock <IOperatingSystem>();

            operatingSystemMock.Setup(osm => osm.IsWindows()).Returns(false);
            operatingSystemMock.Setup(osm => osm.IsOsx()).Returns(true);

            var fileSystem = new FileSystem(typeof(FileSystemIntegrationTests), operatingSystemMock.Object);

            var specialFolderPath = fileSystem.GetCommonApplicationDataFolderPath(Environment.SpecialFolderOption.None);

            specialFolderPath.Should().NotBeNull();

            if (operatingSystem.IsOsx())
            {
                _fileSystem.FolderExists(specialFolderPath).Should().BeTrue();
            }
        }