Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit55d2469

Browse files
committed
enable nullable
1 parentf56c26c commit55d2469

20 files changed

+980
-1025
lines changed

‎Directory.Build.props‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
<PropertyGroup>
3+
<LangVersion>latest</LangVersion>
4+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
5+
<SignAssembly>true</SignAssembly>
6+
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
7+
<PublicSignCondition=" '$(OS)' != 'Windows_NT'">true</PublicSign>
8+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
9+
<Nullable>enable</Nullable>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
</PropertyGroup>
12+
</Project>

‎global.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sdk": {
33
"allowPrerelease":false,
4-
"version":"5.0.201",
4+
"version":"6.0.401",
55
"rollForward":"latestFeature"
66
}
77
}
Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,40 @@
1-
usingSystem;
2-
usingSystem.Collections.Generic;
3-
usingSystem.Diagnostics;
4-
usingSystem.Linq;
5-
usingSystem.Threading;
6-
usingSystem.Threading.Tasks;
1+
usingSystem.Diagnostics;
72
usingMicrosoft.AspNetCore.Mvc;
8-
usingMicrosoft.Extensions.Logging;
93
usingSample.Models;
104
usingSerilog;
115

12-
namespaceSample.Controllers
6+
namespaceSample.Controllers;
7+
8+
publicclassHomeController:Controller
139
{
14-
publicclassHomeController:Controller
10+
staticint_callCount;
11+
12+
readonlyILogger<HomeController>_logger;
13+
readonlyIDiagnosticContext_diagnosticContext;
14+
15+
publicHomeController(ILogger<HomeController>logger,IDiagnosticContextdiagnosticContext)
16+
{
17+
_logger=logger??thrownewArgumentNullException(nameof(logger));
18+
_diagnosticContext=diagnosticContext??thrownewArgumentNullException(nameof(diagnosticContext));
19+
}
20+
21+
publicIActionResultIndex()
22+
{
23+
_logger.LogInformation("Hello, world!");
24+
25+
_diagnosticContext.Set("IndexCallCount",Interlocked.Increment(ref_callCount));
26+
27+
returnView();
28+
}
29+
30+
publicIActionResultPrivacy()
31+
{
32+
thrownewInvalidOperationException("Something went wrong.");
33+
}
34+
35+
[ResponseCache(Duration=0,Location=ResponseCacheLocation.None,NoStore=true)]
36+
publicIActionResultError()
1537
{
16-
staticint_callCount;
17-
18-
readonlyILogger<HomeController>_logger;
19-
readonlyIDiagnosticContext_diagnosticContext;
20-
21-
publicHomeController(ILogger<HomeController>logger,IDiagnosticContextdiagnosticContext)
22-
{
23-
_logger=logger??thrownewArgumentNullException(nameof(logger));
24-
_diagnosticContext=diagnosticContext??thrownewArgumentNullException(nameof(diagnosticContext));
25-
}
26-
27-
publicIActionResultIndex()
28-
{
29-
_logger.LogInformation("Hello, world!");
30-
31-
_diagnosticContext.Set("IndexCallCount",Interlocked.Increment(ref_callCount));
32-
33-
returnView();
34-
}
35-
36-
publicIActionResultPrivacy()
37-
{
38-
thrownewInvalidOperationException("Something went wrong.");
39-
}
40-
41-
[ResponseCache(Duration=0,Location=ResponseCacheLocation.None,NoStore=true)]
42-
publicIActionResultError()
43-
{
44-
returnView(newErrorViewModel{RequestId=Activity.Current?.Id??HttpContext.TraceIdentifier});
45-
}
38+
returnView(newErrorViewModel{RequestId=Activity.Current?.Id??HttpContext.TraceIdentifier});
4639
}
47-
}
40+
}
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
usingSystem;
1+
namespaceSample.Models;
22

3-
namespaceSample.Models
3+
publicclassErrorViewModel
44
{
5-
publicclassErrorViewModel
6-
{
7-
publicstringRequestId{get;set;}
5+
publicstring?RequestId{get;set;}
86

9-
publicboolShowRequestId=>!string.IsNullOrEmpty(RequestId);
10-
}
7+
publicboolShowRequestId=>!string.IsNullOrEmpty(RequestId);
118
}

‎samples/Sample/Program.cs‎

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
1-
usingSystem;
2-
usingSystem.Collections.Generic;
3-
usingSystem.Linq;
4-
usingSystem.Threading.Tasks;
5-
usingMicrosoft.AspNetCore.Hosting;
6-
usingMicrosoft.Extensions.Configuration;
7-
usingMicrosoft.Extensions.Hosting;
8-
usingMicrosoft.Extensions.Logging;
91
usingSerilog;
102

11-
namespaceSample
3+
namespaceSample;
4+
5+
publicstaticclassProgram
126
{
13-
publicstaticclassProgram
7+
publicstaticintMain(string[]args)
148
{
15-
publicstaticintMain(string[]args)
16-
{
17-
// The initial "bootstrap" logger is able to log errors during start-up. It's completely replaced by the
18-
// logger configured in `UseSerilog()` below, once configuration and dependency-injection have both been
19-
// set up successfully.
20-
Log.Logger=newLoggerConfiguration()
21-
.WriteTo.Console()
22-
.CreateBootstrapLogger();
23-
24-
Log.Information("Starting up!");
9+
// The initial "bootstrap" logger is able to log errors during start-up. It's completely replaced by the
10+
// logger configured in `UseSerilog()` below, once configuration and dependency-injection have both been
11+
// set up successfully.
12+
Log.Logger=newLoggerConfiguration()
13+
.WriteTo.Console()
14+
.CreateBootstrapLogger();
2515

26-
try
27-
{
28-
CreateHostBuilder(args).Build().Run();
16+
Log.Information("Starting up!");
2917

30-
Log.Information("Stopped cleanly");
31-
return0;
32-
}
33-
catch(Exceptionex)
34-
{
35-
Log.Fatal(ex,"An unhandled exception occured during bootstrapping");
36-
return1;
37-
}
38-
finally
39-
{
40-
Log.CloseAndFlush();
41-
}
42-
}
18+
try
19+
{
20+
CreateHostBuilder(args).Build().Run();
4321

44-
publicstaticIHostBuilderCreateHostBuilder(string[]args)=>
45-
Host.CreateDefaultBuilder(args)
46-
.UseSerilog((context,services,configuration)=>configuration
47-
.ReadFrom.Configuration(context.Configuration)
48-
.ReadFrom.Services(services)
49-
.Enrich.FromLogContext()
50-
.WriteTo.Console())
51-
.ConfigureWebHostDefaults(webBuilder=>{webBuilder.UseStartup<Startup>();});
22+
Log.Information("Stopped cleanly");
23+
return0;
24+
}
25+
catch(Exceptionex)
26+
{
27+
Log.Fatal(ex,"An unhandled exception occured during bootstrapping");
28+
return1;
29+
}
30+
finally
31+
{
32+
Log.CloseAndFlush();
33+
}
5234
}
53-
}
35+
36+
publicstaticIHostBuilderCreateHostBuilder(string[]args)=>
37+
Host.CreateDefaultBuilder(args)
38+
.UseSerilog((context,services,configuration)=>configuration
39+
.ReadFrom.Configuration(context.Configuration)
40+
.ReadFrom.Services(services)
41+
.Enrich.FromLogContext()
42+
.WriteTo.Console())
43+
.ConfigureWebHostDefaults(webBuilder=>{webBuilder.UseStartup<Startup>();});
44+
}

‎samples/Sample/Sample.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<ProjectSdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

‎samples/Sample/Startup.cs‎

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,53 @@
1-
usingSystem;
2-
usingSystem.Collections.Generic;
3-
usingSystem.Linq;
4-
usingSystem.Threading.Tasks;
5-
usingMicrosoft.AspNetCore.Builder;
6-
usingMicrosoft.AspNetCore.Hosting;
7-
usingMicrosoft.AspNetCore.HttpsPolicy;
8-
usingMicrosoft.Extensions.Configuration;
9-
usingMicrosoft.Extensions.DependencyInjection;
10-
usingMicrosoft.Extensions.Hosting;
111
usingSerilog;
122

13-
namespaceSample
3+
namespaceSample;
4+
5+
publicclassStartup
146
{
15-
publicclassStartup
7+
publicStartup(IConfigurationconfiguration)
168
{
17-
publicStartup(IConfigurationconfiguration)
18-
{
19-
Configuration=configuration;
20-
}
9+
Configuration=configuration;
10+
}
2111

22-
publicIConfigurationConfiguration{get;}
12+
publicIConfigurationConfiguration{get;}
13+
14+
// This method gets called by the runtime. Use this method to add services to the container.
15+
publicvoidConfigureServices(IServiceCollectionservices)
16+
{
17+
services.AddControllersWithViews();
18+
}
2319

24-
// This method gets called by the runtime. Use this method to add services to the container.
25-
publicvoidConfigureServices(IServiceCollectionservices)
20+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
21+
publicvoidConfigure(IApplicationBuilderapp,IWebHostEnvironmentenv)
22+
{
23+
if(env.IsDevelopment())
2624
{
27-
services.AddControllersWithViews();
25+
app.UseDeveloperExceptionPage();
2826
}
29-
30-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
31-
publicvoidConfigure(IApplicationBuilderapp,IWebHostEnvironmentenv)
27+
else
3228
{
33-
if(env.IsDevelopment())
34-
{
35-
app.UseDeveloperExceptionPage();
36-
}
37-
else
38-
{
39-
app.UseExceptionHandler("/Home/Error");
40-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
41-
app.UseHsts();
42-
}
29+
app.UseExceptionHandler("/Home/Error");
30+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
31+
app.UseHsts();
32+
}
4333

44-
app.UseHttpsRedirection();
45-
app.UseStaticFiles();
46-
47-
// Write streamlined request completion events, instead of the more verbose ones from the framework.
48-
// To use the default framework request logging instead, remove this line and set the "Microsoft"
49-
// level in appsettings.json to "Information".
50-
app.UseSerilogRequestLogging();
34+
app.UseHttpsRedirection();
35+
app.UseStaticFiles();
5136

52-
app.UseRouting();
37+
// Write streamlined request completion events, instead of the more verbose ones from the framework.
38+
// To use the default framework request logging instead, remove this line and set the "Microsoft"
39+
// level in appsettings.json to "Information".
40+
app.UseSerilogRequestLogging();
5341

54-
app.UseAuthorization();
42+
app.UseRouting();
5543

56-
app.UseEndpoints(endpoints=>
57-
{
58-
endpoints.MapControllerRoute(
59-
name:"default",
60-
pattern:"{controller=Home}/{action=Index}/{id?}");
61-
});
62-
}
44+
app.UseAuthorization();
45+
46+
app.UseEndpoints(endpoints=>
47+
{
48+
endpoints.MapControllerRoute(
49+
name:"default",
50+
pattern:"{controller=Home}/{action=Index}/{id?}");
51+
});
6352
}
6453
}

‎serilog-aspnetcore.sln‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9
1717
README.md=README.md
1818
assets\Serilog.snk=assets\Serilog.snk
1919
Setup.ps1=Setup.ps1
20+
Directory.Build.props=Directory.Build.props
2021
EndProjectSection
2122
EndProject
2223
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Serilog.AspNetCore","src\Serilog.AspNetCore\Serilog.AspNetCore.csproj","{0549D23F-986B-4FB2-BACE-16FD7A7BC9EF}"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp