Browse Source

Updated logging


			
			
				main
			
			
		
Steve Smith 8 years ago
parent
commit
af406f86ef
  1. 2
      src/Web/Controllers/AccountController.cs
  2. 30
      src/Web/Controllers/CatalogController.cs
  3. 24
      src/Web/Infrastructure/CatalogContextSeed.cs
  4. 6
      src/Web/Program.cs
  5. 2
      src/Web/Properties/launchSettings.json
  6. 20
      src/Web/Startup.cs
  7. 4
      src/Web/Views/Account/Signin.cshtml
  8. 19
      src/Web/Web.csproj
  9. 3
      src/Web/appsettings.json
  10. 0
      src/Web/wwwroot/images/products/1.png
  11. 0
      src/Web/wwwroot/images/products/10.png
  12. 0
      src/Web/wwwroot/images/products/11.png
  13. 0
      src/Web/wwwroot/images/products/12.png
  14. 0
      src/Web/wwwroot/images/products/2.png
  15. 0
      src/Web/wwwroot/images/products/3.png
  16. 0
      src/Web/wwwroot/images/products/4.png
  17. 0
      src/Web/wwwroot/images/products/5.png
  18. 0
      src/Web/wwwroot/images/products/6.png
  19. 0
      src/Web/wwwroot/images/products/7.png
  20. 0
      src/Web/wwwroot/images/products/8.png
  21. 0
      src/Web/wwwroot/images/products/9.png

2
src/Web/Controllers/AccountController.cs

@ -89,7 +89,7 @@ namespace Microsoft.eShopWeb.Controllers
}
else
{
return RedirectToAction(nameof(CatalogController.Index), "Home");
return RedirectToAction(nameof(CatalogController.Index), "Catalog");
}
}

30
src/Web/Controllers/CatalogController.cs

@ -56,21 +56,21 @@ namespace Microsoft.eShopWeb.Controllers
return View(vm);
}
[HttpGet("[controller]/pic/{id}")]
public IActionResult GetImage(int id)
{
byte[] imageBytes;
try
{
imageBytes = _imageService.GetImageBytesById(id);
}
catch (CatalogImageMissingException ex)
{
_logger.LogWarning($"No image found for id: {id}");
return NotFound();
}
return File(imageBytes, "image/png");
}
//[HttpGet("[controller]/pic/{id}")]
//public IActionResult GetImage(int id)
//{
// byte[] imageBytes;
// try
// {
// imageBytes = _imageService.GetImageBytesById(id);
// }
// catch (CatalogImageMissingException ex)
// {
// _logger.LogWarning($"No image found for id: {id}");
// return NotFound();
// }
// return File(imageBytes, "image/png");
//}
public IActionResult Error()

24
src/Web/Infrastructure/CatalogContextSeed.cs

@ -85,18 +85,18 @@
{
return new List<CatalogItem>()
{
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/1" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/2" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/3" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/4" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/5" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/6" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/7" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/8" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/9" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/10" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/11" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/12" }
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/1.png" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://catalogbaseurltobereplaced/images/products/2.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/3.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/4.png" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/5.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/6.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/7.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/8.png" },
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/9.png" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/10.png" },
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/images/products/11.png" },
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/images/products/12.png" }
};
}
}

6
src/Web/Program.cs

@ -1,5 +1,6 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
namespace Microsoft.eShopWeb
{
@ -11,6 +12,11 @@ namespace Microsoft.eShopWeb
.UseKestrel()
.UseUrls("http://0.0.0.0:5106")
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureLogging(factory =>
{
factory.AddConsole(LogLevel.Warning);
factory.AddDebug();
})
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()

2
src/Web/Properties/launchSettings.json

@ -21,7 +21,7 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:58299"
"applicationUrl": "http://localhost:5106"
}
}
}

20
src/Web/Startup.cs

@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http;
using ApplicationCore.Interfaces;
using Infrastructure.FileSystem;
using Infrastructure.Logging;
using Microsoft.AspNetCore.Identity;
namespace Microsoft.eShopWeb
{
@ -41,8 +42,8 @@ namespace Microsoft.eShopWeb
{
try
{
//c.UseInMemoryDatabase("Catalog");
c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
c.UseInMemoryDatabase("Catalog");
//c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
c.ConfigureWarnings(wb =>
{
//By default, in this application, we don't want to have client evaluations
@ -57,8 +58,8 @@ namespace Microsoft.eShopWeb
// Add Identity DbContext
services.AddDbContext<AppIdentityDbContext>(options =>
//options.UseInMemoryDatabase("Identity"));
options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
options.UseInMemoryDatabase("Identity"));
//options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<AppIdentityDbContext>()
@ -76,11 +77,11 @@ namespace Microsoft.eShopWeb
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
UserManager<ApplicationUser> userManager)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
@ -124,6 +125,9 @@ namespace Microsoft.eShopWeb
//Seed Data
CatalogContextSeed.SeedAsync(app, loggerFactory)
.Wait();
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
}
}
}

4
src/Web/Views/Account/Signin.cshtml

@ -7,7 +7,7 @@
}
<div class="brand-header-block">
<ul class="container">
<li><a asp-area="" asp-controller="Account" asp-action="Register">REGISTER</a></li>
@*<li><a asp-area="" asp-controller="Account" asp-action="Register">REGISTER</a></li>*@
<li class="active" style="margin-right: 65px;">LOGIN</li>
</ul>
</div>
@ -15,7 +15,7 @@
<div class="row">
<div class="col-md-12">
<section>
<form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
<form asp-controller="Account" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
<h4>ARE YOU REGISTERED?</h4>
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">

19
src/Web/Web.csproj

@ -41,5 +41,24 @@
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<None Include="wwwroot\images\products\1.png" />
<None Include="wwwroot\images\products\10.png" />
<None Include="wwwroot\images\products\11.png" />
<None Include="wwwroot\images\products\12.png" />
<None Include="wwwroot\images\products\2.png" />
<None Include="wwwroot\images\products\3.png" />
<None Include="wwwroot\images\products\4.png" />
<None Include="wwwroot\images\products\5.png" />
<None Include="wwwroot\images\products\6.png" />
<None Include="wwwroot\images\products\7.png" />
<None Include="wwwroot\images\products\8.png" />
<None Include="wwwroot\images\products\9.png" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

3
src/Web/appsettings.json

@ -8,7 +8,8 @@
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning",
"Microsoft" : "Warning"
"Microsoft": "Warning",
"System": "Warning"
}
}
}

0
src/Web/Pics/1.png → src/Web/wwwroot/images/products/1.png

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

0
src/Web/Pics/10.png → src/Web/wwwroot/images/products/10.png

Before

Width:  |  Height:  |  Size: 223 KiB

After

Width:  |  Height:  |  Size: 223 KiB

0
src/Web/Pics/11.png → src/Web/wwwroot/images/products/11.png

Before

Width:  |  Height:  |  Size: 212 KiB

After

Width:  |  Height:  |  Size: 212 KiB

0
src/Web/Pics/12.png → src/Web/wwwroot/images/products/12.png

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

0
src/Web/Pics/2.png → src/Web/wwwroot/images/products/2.png

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

0
src/Web/Pics/3.png → src/Web/wwwroot/images/products/3.png

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 170 KiB

0
src/Web/Pics/4.png → src/Web/wwwroot/images/products/4.png

Before

Width:  |  Height:  |  Size: 152 KiB

After

Width:  |  Height:  |  Size: 152 KiB

0
src/Web/Pics/5.png → src/Web/wwwroot/images/products/5.png

Before

Width:  |  Height:  |  Size: 226 KiB

After

Width:  |  Height:  |  Size: 226 KiB

0
src/Web/Pics/6.png → src/Web/wwwroot/images/products/6.png

Before

Width:  |  Height:  |  Size: 179 KiB

After

Width:  |  Height:  |  Size: 179 KiB

0
src/Web/Pics/7.png → src/Web/wwwroot/images/products/7.png

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 182 KiB

0
src/Web/Pics/8.png → src/Web/wwwroot/images/products/8.png

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 167 KiB

0
src/Web/Pics/9.png → src/Web/wwwroot/images/products/9.png

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Loading…
Cancel
Save