当前位置: 首页>>代码示例>>C#>>正文


C# IHostingEnvironment.IsStaging方法代码示例

本文整理汇总了C#中IHostingEnvironment.IsStaging方法的典型用法代码示例。如果您正苦于以下问题:C# IHostingEnvironment.IsStaging方法的具体用法?C# IHostingEnvironment.IsStaging怎么用?C# IHostingEnvironment.IsStaging使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHostingEnvironment的用法示例。


在下文中一共展示了IHostingEnvironment.IsStaging方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Startup

        public Startup(IHostingEnvironment env)
        {
            // Setup configuration sources.
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("version.json")
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();

            if (env.IsDevelopment())
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();

                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }
            else if (env.IsStaging() || env.IsProduction())
            {
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: false);
            }

            Configuration = builder.Build();

            Configuration["version"] = new ApplicationEnvironment().ApplicationVersion; // version in project.json
        }
开发者ID:ChrisDobby,项目名称:allReady,代码行数:29,代码来源:Startup.cs

示例2: Configure

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddNLog(Configuration);
            app.AddNLogWeb();

            app
                .UseIISPlatformHandler()
                .UseApplicationInsightsRequestTelemetry()
                .UseApplicationInsightsExceptionTelemetry()
                .UseApiExceptionResponse(env.IsDevelopment() || env.IsStaging());

            var virtualPath = Environment.GetEnvironmentVariable("VIRTUAL_PATH");
            if (string.IsNullOrEmpty(virtualPath) == false)
                app.Map(virtualPath, x => ConfigureInternal(x, env, loggerFactory));
            else
                ConfigureInternal(app, env, loggerFactory);

            app.Map("/throw", throwApp => throwApp.Run(context =>
                                                       {
                                                           throw new Exception("Test Exception",
                                                               new Exception("Test Inner Exception",
                                                                   new Exception("Test Inner Inner Exception")));
                                                       }));
        }
开发者ID:litichevskiydv,项目名称:DnxTestWebApp,代码行数:24,代码来源:Startup.cs

示例3: Configure

        // Configure is called after ConfigureServices is called.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SampleDataGenerator sampleData, AllReadyContext context, 
            IConfiguration configuration)
        {
            // todo: in RC update we can read from a logging.json config file
            loggerFactory.AddConsole((category, level) =>
            {
                if (category.StartsWith("Microsoft."))
                {
                    return level >= LogLevel.Information;
                }
                return true;
            });

            if (env.IsDevelopment())
            {
                // this will go to the VS output window
                loggerFactory.AddDebug((category, level) =>
                {
                    if (category.StartsWith("Microsoft."))
                    {
                        return level >= LogLevel.Information;
                    }
                    return true;
                });
            }

            // CORS support
            app.UseCors("allReady");

            // Configure the HTTP request pipeline.
            var usCultureInfo = new CultureInfo("en-US");
            app.UseRequestLocalization(new RequestLocalizationOptions
            {
                SupportedCultures = new List<CultureInfo>(new[] { usCultureInfo }),
                SupportedUICultures = new List<CultureInfo>(new[] { usCultureInfo })
            });

            // Add Application Insights to the request pipeline to track HTTP request telemetry data.
            app.UseApplicationInsightsRequestTelemetry();

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else if (env.IsStaging())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // sends the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            // Track data about exceptions from the application. Should be configured after all error handling middleware in the request pipeline.
            app.UseApplicationInsightsExceptionTelemetry();

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add token-based protection to the request inject pipeline
            app.UseTokenProtection(new TokenProtectedResourceOptions
            {
                Path = "/api/request",
                PolicyName = "api-request-injest"
            });

            // Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
            // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
            if (Configuration["Authentication:Facebook:AppId"] != null)
            {
                var options = new FacebookOptions
                {
                    AppId = Configuration["Authentication:Facebook:AppId"],
                    AppSecret = Configuration["Authentication:Facebook:AppSecret"],
                    BackchannelHttpHandler = new FacebookBackChannelHandler(),
                    UserInformationEndpoint = "https://graph.facebook.com/v2.5/me?fields=id,name,email,first_name,last_name"
                };
                options.Scope.Add("email");

                app.UseFacebookAuthentication(options);
            }

            if (Configuration["Authentication:MicrosoftAccount:ClientId"] != null)
            {
                var options = new MicrosoftAccountOptions
                {
                    ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"],
                    ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"]
                };

//.........这里部分代码省略.........
开发者ID:mheggeseth,项目名称:allReady,代码行数:101,代码来源:Startup.cs

示例4: AddStandardLog

 public static void AddStandardLog(this ILoggerFactory loggerFactory, IHostingEnvironment env)
 {
     if (env.IsDevelopment())
     {
         loggerFactory.MinimumLevel = LogLevel.Debug;
         loggerFactory.AddLog4Net(LogLevel.Information);
         //loggerFactory.AddDebug(LogLevel.Debug);
         loggerFactory.AddDebug((t, l) =>
         {
             if (t.StartsWith("Microsoft") && ( l == LogLevel.Verbose || l == LogLevel.Debug))
             {
                 return false;
             }
             return true;
         });
     }
     else if (env.IsStaging())
     {
         loggerFactory.AddLog4Net(LogLevel.Information);
     }
     else
     {
         loggerFactory.AddLog4Net(LogLevel.Warning);
     }
 }
开发者ID:asimshah,项目名称:apollo-web,代码行数:25,代码来源:Logger.cs


注:本文中的IHostingEnvironment.IsStaging方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。