private static void AddDefaultServices(IServiceCollection services)
 {
     dummyVar0  = LoggingServiceCollectionExtensions.AddLogging(services);
     dummyVar1  = OptionsServiceCollectionExtensions.AddOptions(services);
     dummyVar2  = LocalizationServiceCollectionExtensions.AddLocalization(services);
     dummyVar3  = ServiceCollectionServiceExtensions.AddSingleton <IStringLocalizerFactory, NullStringLocalizerFactory>(services);
     dummyVar4  = ServiceCollectionServiceExtensions.AddSingleton <IHtmlLocalizerFactory, NullHtmlLocalizerFactory>(services);
     dummyVar5  = EncoderServiceCollectionExtensions.AddWebEncoders(services);
     dummyVar6  = HttpServiceCollectionExtensions.AddHttpContextAccessor(services);
     dummyVar7  = ServiceCollectionServiceExtensions.AddSingleton <IClock, Clock>(services);
     dummyVar8  = ServiceCollectionServiceExtensions.AddScoped <ILocalClock, LocalClock>(services);
     dummyVar9  = ServiceCollectionServiceExtensions.AddScoped <ILocalizationService, DefaultLocalizationService>(services);
     dummyVar10 = ServiceCollectionServiceExtensions.AddScoped <ICalendarManager, DefaultCalendarManager>(services);
     dummyVar11 = ServiceCollectionServiceExtensions.AddScoped <ICalendarSelector, DefaultCalendarSelector>(services);
     dummyVar12 = ServiceCollectionServiceExtensions.AddSingleton <IPoweredByMiddlewareOptions, PoweredByMiddlewareOptions>(services);
     dummyVar13 = ServiceCollectionServiceExtensions.AddScoped <IOrchardHelper, DefaultOrchardHelper>(services);
     return;
 }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        /// <param name="logAction">logAction</param>
        /// <para>e.g. .Logs or wwwroor/logs or C:/wwwroot/logs</para>
        public static IServiceCollection AddFileLog(this IServiceCollection services, Action <LogOptions> logAction = null)
        {
            bool flag = !services.Any((ServiceDescriptor x) => x.ImplementationType == typeof(LoggerFactory));

            if (flag)
            {
                LogOptions logOptions = new LogOptions();
                if (logAction != null)
                {
                    logAction(logOptions);
                }
                services.Replace(ServiceDescriptor.Transient <IApplicationBuilderFactory, DefaultApplicationBuilderFactory>());
                LoggerSettings.Format           = logOptions.Format;
                LoggerFactory.ServiceCollection = services;
                bool flag2 = string.IsNullOrEmpty(logOptions.LogDirectory);
                if (flag2)
                {
                    logOptions.LogDirectory = ".Logs";
                }
                services.AddHttpContextAccessor();
                services.AddSingleton <ILogAdapter, FileLogAdapter>();
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                Console.OutputEncoding = Encoding.UTF8;
                ServiceDescriptor serviceDescriptor = services.FirstOrDefault((ServiceDescriptor x) => x.ServiceType == typeof(IConfiguration));
                IConfiguration    _config           = ((serviceDescriptor != null) ? serviceDescriptor.ImplementationInstance : null) as IConfiguration;
                bool flag3 = _config == null;
                if (flag3)
                {
                    _config = FileConfigurationExtensions.SetBasePath(EnvironmentVariablesExtensions.AddEnvironmentVariables(new ConfigurationBuilder(), "ASPNETCORE_"), AppContext.BaseDirectory).Build();
                    _config[WebHostDefaults.ContentRootKey] = AppContext.BaseDirectory;
                    services.AddSingleton(_config);
                }
                bool flag4 = string.IsNullOrEmpty(_config[WebHostDefaults.ContentRootKey]);
                if (flag4)
                {
                    _config[WebHostDefaults.ContentRootKey] = AppContext.BaseDirectory;
                }
                ServiceDescriptor   serviceDescriptor2 = services.FirstOrDefault((ServiceDescriptor x) => x.ServiceType == typeof(IHostingEnvironment));
                IHostingEnvironment environment        = (IHostingEnvironment)((serviceDescriptor2 != null) ? serviceDescriptor2.ImplementationInstance : null);
                bool flag5 = environment == null;
                if (flag5)
                {
                    WebHostOptions options = new WebHostOptions(_config, Assembly.GetEntryAssembly().GetName().Name);
                    environment = new HostingEnvironment();
                    HostingEnvironmentExtensions.Initialize(environment, AppContext.BaseDirectory, options);
                    services.TryAddSingleton(environment);
                }
                bool flag6 = string.IsNullOrEmpty(environment.WebRootPath);
                if (flag6)
                {
                    string _contentPath = _config[WebHostDefaults.ContentRootKey];
                    int    binIndex     = _contentPath.LastIndexOf("\\bin\\");
                    bool   flag7        = binIndex > -1;
                    if (flag7)
                    {
                        string contentPath = _contentPath.Substring(0, binIndex);
                        bool   flag8       = contentPath.IndexOf(environment.ApplicationName) > -1;
                        if (flag8)
                        {
                            _config[WebHostDefaults.ContentRootKey] = contentPath;
                            environment.ContentRootPath             = contentPath;
                            environment.WebRootPath = Path.Combine(contentPath, "wwwroot");
                        }
                        else
                        {
                            environment.WebRootPath = _contentPath;
                        }
                    }
                    else
                    {
                        environment.WebRootPath = Path.Combine(_config["ContentRoot"], "wwwroot");
                    }
                }
                bool flag9 = Path.IsPathRooted(logOptions.LogDirectory);
                if (flag9)
                {
                    LoggerSettings.LogDirectory = logOptions.LogDirectory;
                }
                else
                {
                    LoggerSettings.LogDirectory = Path.Combine(_config["ContentRoot"], logOptions.LogDirectory);
                }
                bool flag10 = !Directory.Exists(LoggerSettings.LogDirectory);
                if (flag10)
                {
                    Directory.CreateDirectory(LoggerSettings.LogDirectory);
                }
                string path   = Path.Combine(LoggerSettings.LogDirectory, "_logging.json");
                bool   flag11 = !File.Exists(path);
                if (flag11)
                {
                    File.AppendAllText(path, "{\"Rules\":[{\"CategoryName\":\"Default\",\"LogLevel\":\"Information\",\"LogType\":\"All\",\"TraceCount\":5}]}");
                }
                ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
                JsonConfigurationExtensions.AddJsonFile(FileConfigurationExtensions.SetBasePath(configurationBuilder, environment.ContentRootPath), path, true, true);
                IConfigurationRoot configuration = configurationBuilder.Build();
                services.RemoveAll <ILoggerProviderConfigurationFactory>();
                services.RemoveAll(typeof(ILoggerProviderConfiguration <>));
                TypeInfo type = typeof(ILoggerProviderConfigurationFactory).Assembly.DefinedTypes.SingleOrDefault((TypeInfo t) => t.Name == "LoggingConfiguration");
                services.RemoveAll(type);

                LoggingServiceCollectionExtensions.AddLogging(services, delegate(ILoggingBuilder x)
                {
                    x.AddConfiguration(configuration);
                    //bool flag13 = !x.Services.Any((ServiceDescriptor t) => t.ServiceType == typeof(ILoggerProvider));
                    //if (flag13)
                    //{
                    //    ConsoleLoggerExtensions.AddConsole(x);
                    //}
                    x.Services.RemoveAll <IConfigureOptions <LoggerFilterOptions> >();
                    x.Services.AddSingleton(new LoggerFilterConfigureOptions(configuration));
                });
                services.Replace(ServiceDescriptor.Singleton <ILoggerFactory, LoggerFactory>());
                services.Replace(ServiceDescriptor.Singleton <DiagnosticSource>(new DefaultDiagnosticListener()));
                bool flag12 = services.IsHttpRequest();
                if (flag12)
                {
                    MarkdownFileMiddleware.SaveResourceFiles(environment.WebRootPath);
                }
                DefaultApplicationBuilderFactory.OnCreateBuilder(new Action <IApplicationBuilder, object>(LoggerExtensions.UseFileLog), logOptions);
            }
            return(services);
        }