From a6bf0e16aa6c2e71da0ea46a1d241c311754fcf7 Mon Sep 17 00:00:00 2001 From: Praburaj Date: Fri, 9 Jan 2015 15:12:53 -0800 Subject: [PATCH] Adding console logger to the sample --- src/MusicStore/Startup.cs | 32 ++++++++++++------- src/MusicStore/StartupNtlmAuthentication.cs | 6 +++- src/MusicStore/project.json | 13 +++++--- .../shared/Mocks/StartupSocialTesting.cs | 6 +++- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 7198537f82..d0e2dcf1e8 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -7,6 +7,8 @@ using Microsoft.AspNet.Routing; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; +using Microsoft.Framework.Logging.Console; using MusicStore.Models; namespace MusicStore @@ -87,8 +89,10 @@ namespace MusicStore //This method is invoked when ASPNET_ENV is 'Development' or is not defined //The allowed values are Development,Staging and Production - public void ConfigureDevelopment(IApplicationBuilder app) + public void ConfigureDevelopment(IApplicationBuilder app, ILoggerFactory loggerFactory) { + loggerFactory.AddConsole(); + //Display custom error page in production when error occurs //During development use the ErrorPage middleware to display error information in the browser app.UseErrorPage(ErrorPageOptions.ShowAll); @@ -105,17 +109,23 @@ namespace MusicStore //This method is invoked when ASPNET_ENV is 'Staging' //The allowed values are Development,Staging and Production - public void ConfigureStaging(IApplicationBuilder app) + public void ConfigureStaging(IApplicationBuilder app, ILoggerFactory loggerFactory) { + loggerFactory.AddConsole(); + app.UseErrorHandler("/Home/Error"); + Configure(app); } //This method is invoked when ASPNET_ENV is 'Production' //The allowed values are Development,Staging and Production - public void ConfigureProduction(IApplicationBuilder app) + public void ConfigureProduction(IApplicationBuilder app, ILoggerFactory loggerFactory) { + loggerFactory.AddConsole(); + app.UseErrorHandler("/Home/Error"); + Configure(app); } @@ -136,20 +146,20 @@ namespace MusicStore app.UseTwitterAuthentication(); - //The MicrosoftAccount service has restrictions that prevent the use of http://localhost:5001/ for test applications. - //As such, here is how to change this sample to uses http://ktesting.com:5001/ instead. + // The MicrosoftAccount service has restrictions that prevent the use of http://localhost:5001/ for test applications. + // As such, here is how to change this sample to uses http://ktesting.com:5001/ instead. - //Edit the Project.json file and replace http://localhost:5001/ with http://ktesting.com:5001/. + // Edit the Project.json file and replace http://localhost:5001/ with http://ktesting.com:5001/. - //From an admin command console first enter: + // From an admin command console first enter: // notepad C:\Windows\System32\drivers\etc\hosts - //and add this to the file, save, and exit (and reboot?): + // and add this to the file, save, and exit (and reboot?): // 127.0.0.1 ktesting.com - //Then you can choose to run the app as admin (see below) or add the following ACL as admin: - // netsh http add urlacl url=http://ktesting:12345/ user=[domain\user] + // Then you can choose to run the app as admin (see below) or add the following ACL as admin: + // netsh http add urlacl url=http://ktesting:5001/ user=[domain\user] - //The sample app can then be run via: + // The sample app can then be run via: // k web app.UseMicrosoftAccountAuthentication(); diff --git a/src/MusicStore/StartupNtlmAuthentication.cs b/src/MusicStore/StartupNtlmAuthentication.cs index edb901056a..474b845d5e 100644 --- a/src/MusicStore/StartupNtlmAuthentication.cs +++ b/src/MusicStore/StartupNtlmAuthentication.cs @@ -9,6 +9,8 @@ using Microsoft.AspNet.Server.WebListener; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; +using Microsoft.Framework.Logging.Console; using Microsoft.Net.Http.Server; using MusicStore.Models; @@ -40,8 +42,10 @@ namespace MusicStore public IConfiguration Configuration { get; private set; } - public void Configure(IApplicationBuilder app) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { + loggerFactory.AddConsole(); + //Set up NTLM authentication for WebListener like below. //For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or modify the applicationHost.config to enable NTLM. if ((app.Server as ServerInformation) != null) diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index 14f5402a86..5ac5465ba7 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -5,7 +5,10 @@ "description": "Music store application on ASP.NET 5", "version": "1.0.0-*", "compilationOptions": { "warningsAsErrors": true, "define": [ "DEMO", "TESTING" ] }, - "code": [ "**/*.cs", "../../test/E2ETests/compiler/shared/**/*.cs" ], // Code from ../../test/E2ETests/compiler/shared folder is for testing only. + "code": [ + "**/*.cs", + "../../test/E2ETests/compiler/shared/**/*.cs" // This code is for testing only. + ], "packExclude": "*.cmd", "webroot": "wwwroot", "dependencies": { @@ -26,13 +29,15 @@ "Microsoft.AspNet.SignalR.Server": "3.0.0-*", "Microsoft.AspNet.StaticFiles": "1.0.0-*", "Microsoft.Framework.Cache.Memory": "1.0.0-*", + "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-*", "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*", - "Microsoft.Framework.OptionsModel": "1.0.0-*" + "Microsoft.Framework.Logging.Console": "1.0.0-*" }, "commands": { - "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002", + "gen": "Microsoft.Framework.CodeGeneration", "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004", - "run": "run server.urls=http://localhost:5003" + "run": "run server.urls=http://localhost:5003", + "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5002" }, "frameworks": { "aspnet50": { }, diff --git a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs index 3a2980f724..a6abe4c1cf 100644 --- a/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs +++ b/test/E2ETests/compiler/shared/Mocks/StartupSocialTesting.cs @@ -14,6 +14,8 @@ using Microsoft.AspNet.Security.Twitter; using Microsoft.Framework.Cache.Memory; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; +using Microsoft.Framework.Logging; +using Microsoft.Framework.Logging.Console; using Microsoft.Framework.Runtime; using MusicStore.Mocks.Common; using MusicStore.Mocks.Facebook; @@ -43,8 +45,10 @@ namespace MusicStore public IConfiguration Configuration { get; private set; } - public void Configure(IApplicationBuilder app) + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { + loggerFactory.AddConsole(); + //Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline. //Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. app.UseErrorPage(ErrorPageOptions.ShowAll);