-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
53 lines (44 loc) · 2.02 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpLogging;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.DependencyInjection;
namespace Rff;
internal class Program
{
private static void Main(string[] args)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpLogging(options =>
{
options.LoggingFields = HttpLoggingFields.All;
});
// 標準の出力を切ってXMLに限定する https://docs.microsoft.com/ja-jp/aspnet/core/web-api/advanced/formatting?view=aspnetcore-6.0
builder.Services.AddControllers(options =>
{
options.OutputFormatters.RemoveType<StringOutputFormatter>();
options.OutputFormatters.RemoveType<SystemTextJsonOutputFormatter>();
}).AddXmlSerializerFormatters();
// XML出力でXML Declarationが消えないようにして改行入れる
builder.Services.Configure<MvcOptions>(options =>
{
XmlSerializerOutputFormatter? xmlWriterSettings = options.OutputFormatters
.OfType<XmlSerializerOutputFormatter>()
.FirstOrDefault();
if (xmlWriterSettings != null)
{
xmlWriterSettings.WriterSettings.OmitXmlDeclaration = false;
xmlWriterSettings.WriterSettings.Indent = true;
}
});
WebApplication app = builder.Build();
app.UseHttpLogging();
// 静的ファイルの提供 https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/static-files?view=aspnetcore-6.0
app.UseFileServer();
// 属性ルーティングの有効化 https://docs.microsoft.com/ja-jp/aspnet/core/mvc/controllers/routing?view=aspnetcore-6.0#attribute-routing-for-rest-apis
// APIでは規則ルーティングを使わないらしい
app.MapControllers();
app.Run();
}
}