GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 加入log4net日志处理类 · feier09/Emma.Blog@42b262b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Emma.Blog.Common
    • Emma.Blog.Common.csproj
    • LogHelper.cs
  • Emma.Blog.Service
    • MyHttpContext.cs
    • ServiceProvider.cs
  • Emma.Blog.WebApi
    • Startup.cs
  • Emma.Blog.Web
    • Controllers
      • HomeController.cs
      • UserController.cs
    • Emma.Blog.Web.csproj
    • Extensions
      • JwtDataFormat.cs
    • MyCookieManager.cs
    • Program.cs
    • Properties/PublishProfiles
      • FolderProfile.pubxml
    • Startup.cs
    • appsettings.json
    • log4net.config
    • log/2018/201801
      • 20180109.txt
  • Emma.Blog.sln
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Emma.Blog.Common/Emma.Blog.Common.csproj‎

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="log4net" Version="2.0.8" />
9+
</ItemGroup>
10+
11+
</Project>
Collapse file

‎Emma.Blog.Common/LogHelper.cs‎

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.IO;
4+
using log4net;
5+
using log4net.Config;
6+
using log4net.Repository;
7+
8+
9+
namespace Emma.Blog.Common
10+
{
11+
12+
public class LogHelper
13+
{
14+
private static ILog logger;
15+
static LogHelper()
16+
{
17+
18+
ILoggerRepository repository = LogManager.CreateRepository("NETCoreRepository");
19+
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
20+
logger = LogManager.GetLogger(repository.Name, "NETCorelog4net");
21+
}
22+
23+
24+
public static void Error(object message, Exception ex)
25+
{
26+
logger.Error(message, ex);
27+
}
28+
29+
30+
public static void Error(object message)
31+
{
32+
logger.Error(message);
33+
}
34+
35+
public static void Info(object message, Exception ex)
36+
{
37+
logger.Error(message, ex);
38+
}
39+
40+
public static void Info(object message)
41+
{
42+
logger.Info(message);
43+
}
44+
45+
46+
47+
48+
}
49+
}
Collapse file

‎Emma.Blog.Service/MyHttpContext.cs‎

Copy file name to clipboardExpand all lines: Emma.Blog.Service/MyHttpContext.cs
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Emma.Blog.Service
88

99
public static class MyHttpContext
1010
{
11-
public static IServiceProvider ServiceProvider;
12-
13-
static MyHttpContext()
14-
{ }
15-
1611

1712
public static HttpContext Current
1813
{
Collapse file

‎Emma.Blog.Service/ServiceProvider.cs‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Emma.Blog.Service
6+
{
7+
public static class ServiceProvider
8+
{
9+
public static IServiceProvider Provider;
10+
11+
static ServiceProvider()
12+
{
13+
14+
}
15+
public static object GetService(Type serviceType)
16+
{
17+
return Provider.GetService(serviceType: serviceType);
18+
19+
}
20+
}
21+
}
Collapse file

‎Emma.Blog.Web/Controllers/HomeController.cs‎

Copy file name to clipboardExpand all lines: Emma.Blog.Web/Controllers/HomeController.cs
+12-10Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Emma.Blog.Data;
7-
using Emma.Blog.Data.Models;
8-
using Emma.Blog.Service;
9-
using Microsoft.AspNetCore.Mvc;
1+
using Emma.Blog.Data.Models;
2+
using Emma.Blog.Service.Account;
103
using Emma.Blog.Web.Models;
114
using Microsoft.AspNetCore.Authorization;
5+
using Microsoft.AspNetCore.Mvc;
6+
using System.Diagnostics;
127

138
namespace Emma.Blog.Web.Controllers
149
{
1510
public class HomeController : Controller
1611
{
17-
12+
1813
public IActionResult Index()
1914
{
15+
16+
UserService service = new UserService();
17+
18+
var claimUser = service.Register(new User()
19+
{
20+
NickName = "mysql"
21+
});
2022
return View();
2123
}
2224

Collapse file

‎Emma.Blog.Web/Controllers/UserController.cs‎

Copy file name to clipboardExpand all lines: Emma.Blog.Web/Controllers/UserController.cs
+15-13Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using Emma.Blog.Service.Auth;
1+
using Emma.Blog.Data.Models;
2+
using Emma.Blog.Service.Account;
3+
using Emma.Blog.Service.Auth;
24
using Microsoft.AspNetCore.Authentication;
35
using Microsoft.AspNetCore.Authentication.Cookies;
46
using Microsoft.AspNetCore.Authorization;
57
using Microsoft.AspNetCore.Mvc;
68
using Microsoft.Extensions.Options;
79
using System;
8-
using System.Collections.Generic;
910
using System.Security.Claims;
10-
using Emma.Blog.Data.Models;
11-
using Emma.Blog.Service.Account;
1211

1312

1413
namespace Emma.Blog.Web.Controllers
@@ -39,17 +38,20 @@ public IActionResult Login()
3938
[HttpPost]
4039
public IActionResult Login(User user)
4140
{
42-
UserService service = new UserService();
43-
var claimUser = service.Register(user);
41+
42+
UserService service = new UserService();
43+
var claimUser = service.Register(user);
4444

45-
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claimUser.GetClaims(), CookieAuthenticationDefaults.AuthenticationScheme));
46-
HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties()
47-
{
48-
IsPersistent = true,
49-
ExpiresUtc = DateTime.UtcNow.AddSeconds(_jwtSettings.Expires)
50-
});
45+
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claimUser.GetClaims(), CookieAuthenticationDefaults.AuthenticationScheme));
46+
HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, new AuthenticationProperties()
47+
{
48+
IsPersistent = true,
49+
ExpiresUtc = DateTime.UtcNow.AddSeconds(_jwtSettings.Expires)
50+
});
5151

52-
return RedirectToAction("Index","Home");
52+
return RedirectToAction("Index", "Home");
53+
54+
5355

5456
}
5557

Collapse file

‎Emma.Blog.Web/Emma.Blog.Web.csproj‎

Copy file name to clipboardExpand all lines: Emma.Blog.Web/Emma.Blog.Web.csproj
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
99
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
1010
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
11+
1112
</ItemGroup>
1213

1314
<ItemGroup>
@@ -16,6 +17,7 @@
1617
</ItemGroup>
1718

1819
<ItemGroup>
20+
<ProjectReference Include="..\Emma.Blog.Common\Emma.Blog.Common.csproj" />
1921
<ProjectReference Include="..\Emma.Blog.Service\Emma.Blog.Service.csproj" />
2022
</ItemGroup>
2123

Collapse file

‎Emma.Blog.Web/Extensions/JwtDataFormat.cs‎

Copy file name to clipboardExpand all lines: Emma.Blog.Web/Extensions/JwtDataFormat.cs
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Security.Claims;
44
using System.Text;
55
using Emma.Blog.Service.Auth;
6-
using Emma.Blog.Web.Models;
76
using Microsoft.AspNetCore.Authentication;
87
using Microsoft.AspNetCore.Authentication.Cookies;
98
using Microsoft.IdentityModel.Tokens;
Collapse file

‎Emma.Blog.Web/MyCookieManager.cs‎

Copy file name to clipboardExpand all lines: Emma.Blog.Web/MyCookieManager.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public void AppendResponseCookie(HttpContext context, string key, string value,
1414

1515
foreach (var item in context.User.Claims)
1616
{
17-
Console.WriteLine("==================claimstype:"+item.Type+",claimsValue:"+item.Value);
17+
Console.WriteLine("==================claimstype:" + item.Type + ",claimsValue:" + item.Value);
1818
}
19-
Console.WriteLine("AppendResponseCookie===================key:" + key+",value:"+value);
19+
Console.WriteLine("AppendResponseCookie===================key:" + key + ",value:" + value);
2020

2121
context.Response.Cookies.Append(key, value);
2222
}
@@ -29,7 +29,7 @@ public void DeleteCookie(HttpContext context, string key, CookieOptions options)
2929
public string GetRequestCookie(HttpContext context, string key)
3030
{
3131
var cookieValue = context.Request.Cookies[key];
32-
Console.WriteLine("GetRequestCookie==================="+key+",value="+cookieValue);
32+
Console.WriteLine("GetRequestCookie===================" + key + ",value=" + cookieValue);
3333
return cookieValue;
3434
}
3535
}
Collapse file

‎Emma.Blog.Web/Program.cs‎

Copy file name to clipboard
+10-11Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Emma.Blog.Data;
7-
using Microsoft.AspNetCore;
1+
using Microsoft.AspNetCore;
82
using Microsoft.AspNetCore.Hosting;
9-
using Microsoft.Extensions.Configuration;
10-
using Microsoft.Extensions.DependencyInjection;
113
using Microsoft.Extensions.Logging;
124

135
namespace Emma.Blog.Web
@@ -16,15 +8,22 @@ public class Program
168
{
179
public static void Main(string[] args)
1810
{
11+
1912
var host = BuildWebHost(args);
2013

2114
host.Run();
22-
15+
2316
}
2417

2518
public static IWebHost BuildWebHost(string[] args) =>
2619
WebHost.CreateDefaultBuilder(args)
2720
.UseStartup<Startup>()
28-
.Build();
21+
.UseKestrel()
22+
23+
.UseStartup<Startup>()
24+
.Build();
25+
26+
27+
2928
}
3029
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.