[CP] Logs

This commit is contained in:
hydrant
2019-09-22 15:16:05 +02:00
parent 10833a5285
commit d29f6acbf5
5 changed files with 85 additions and 21 deletions

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models; using ReallifeGamemode.Database.Models;
@@ -25,6 +27,8 @@ namespace ReallifeGamemode.DataService.Controllers
} }
[HttpGet("Data")] [HttpGet("Data")]
[ProducesResponseType(typeof(GetUserDataResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult<GetUserDataResponse> Data() public ActionResult<GetUserDataResponse> Data()
{ {
User user = dbContext.Users.Where(u => u.Id == UserId).FirstOrDefault(); User user = dbContext.Users.Where(u => u.Id == UserId).FirstOrDefault();

View File

@@ -18,13 +18,19 @@ namespace ReallifeGamemode.DataService
BuildWebHost(args).Run(); BuildWebHost(args).Run();
} }
public static IWebHost BuildWebHost(string[] args) => public static IWebHost BuildWebHost(string[] args)
WebHost.CreateDefaultBuilder(args) {
.UseStartup<Startup>() return WebHost.CreateDefaultBuilder(args)
.UseKestrel(k => .ConfigureLogging((ctx, l) =>
{ {
k.Listen(IPAddress.Any, 5000); l.AddLog4Net(Path.Combine(ctx.HostingEnvironment.ContentRootPath, "log4net.config"));
}) })
.Build(); .UseStartup<Startup>()
.UseKestrel(k =>
{
k.Listen(IPAddress.Any, 5000);
})
.Build();
}
} }
} }

View File

@@ -7,22 +7,31 @@
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="logs\**" />
<Content Remove="logs\**" />
<EmbeddedResource Remove="logs\**" />
<None Remove="logs\**" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="wwwroot\" /> <Folder Include="wwwroot\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="2.2.12" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.5.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.5.0" />
</ItemGroup> </ItemGroup>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -12,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using ReallifeGamemode.Database.Models; using ReallifeGamemode.Database.Models;
using ReallifeGamemode.DataService.Logic; using ReallifeGamemode.DataService.Logic;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
@@ -33,10 +35,7 @@ namespace ReallifeGamemode.DataService
{ {
services.Configure<ServerConfig>(cfg => Configuration.Bind(cfg)); services.Configure<ServerConfig>(cfg => Configuration.Bind(cfg));
services.AddDbContext<DatabaseContext>(db => services.AddDbContext<DatabaseContext>();
{
db.UseMySql(Configuration["ConnectionString"]);
});
services.AddLogic(); services.AddLogic();
@@ -78,35 +77,46 @@ namespace ReallifeGamemode.DataService
services.AddSwaggerGen(c => services.AddSwaggerGen(c =>
{ {
Info info = new Info OpenApiInfo info = new OpenApiInfo
{ {
Title = "GTA:V ControlPanl DataService", Title = "GTA:V ControlPanl DataService",
Version = "0.1", Version = "0.1",
}; };
if(debugToken != null) if (debugToken != null)
{ {
info.Description = $"Debug-Token: {debugToken}"; info.Description = $"Debug-Token: {debugToken}";
} }
c.SwaggerDoc("DataService", info); c.SwaggerDoc("DataService", info);
c.AddSecurityDefinition("Bearer", new ApiKeyScheme c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{ {
Name = "Authorization", Name = "Authorization",
In = "Header", In = ParameterLocation.Header,
Type = "apiKey" Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
}); });
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>() c.AddSecurityRequirement(new OpenApiSecurityRequirement()
{ {
{ "Bearer", new string[] { } } {
new OpenApiSecurityScheme()
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
new string[] {}
}
}); });
}); });
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{ {
app.UseAuthentication(); app.UseAuthentication();

View File

@@ -0,0 +1,35 @@
<log4net xmlns="http://csharptest.net/downloads/schema/log4net.xsd">
<appender name="AllRollingFile" type="log4net.Appender.RollingFileAppender">
<file value="log\" />
<datePattern value="dd.MM.yyyy'.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<threshold value="All" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="ErrorRollingFile" type="log4net.Appender.RollingFileAppender">
<file value="log\" />
<datePattern value="dd.MM.yyyy'.err'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<threshold value="Warn" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="AllRollingFile" />
<appender-ref ref="ErrorRollingFile" />
</root>
</log4net>