[CP] Logs
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
@@ -25,6 +27,8 @@ namespace ReallifeGamemode.DataService.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("Data")]
|
||||
[ProducesResponseType(typeof(GetUserDataResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public ActionResult<GetUserDataResponse> Data()
|
||||
{
|
||||
User user = dbContext.Users.Where(u => u.Id == UserId).FirstOrDefault();
|
||||
|
||||
@@ -18,8 +18,13 @@ namespace ReallifeGamemode.DataService
|
||||
BuildWebHost(args).Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
public static IWebHost BuildWebHost(string[] args)
|
||||
{
|
||||
return WebHost.CreateDefaultBuilder(args)
|
||||
.ConfigureLogging((ctx, l) =>
|
||||
{
|
||||
l.AddLog4Net(Path.Combine(ctx.HostingEnvironment.ContentRootPath, "log4net.config"));
|
||||
})
|
||||
.UseStartup<Startup>()
|
||||
.UseKestrel(k =>
|
||||
{
|
||||
@@ -28,3 +33,4 @@ namespace ReallifeGamemode.DataService
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,31 @@
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="logs\**" />
|
||||
<Content Remove="logs\**" />
|
||||
<EmbeddedResource Remove="logs\**" />
|
||||
<None Remove="logs\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="log4net" Version="2.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</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.Design" Version="1.1.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.DataService.Logic;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
@@ -33,10 +35,7 @@ namespace ReallifeGamemode.DataService
|
||||
{
|
||||
services.Configure<ServerConfig>(cfg => Configuration.Bind(cfg));
|
||||
|
||||
services.AddDbContext<DatabaseContext>(db =>
|
||||
{
|
||||
db.UseMySql(Configuration["ConnectionString"]);
|
||||
});
|
||||
services.AddDbContext<DatabaseContext>();
|
||||
|
||||
services.AddLogic();
|
||||
|
||||
@@ -78,7 +77,7 @@ namespace ReallifeGamemode.DataService
|
||||
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
Info info = new Info
|
||||
OpenApiInfo info = new OpenApiInfo
|
||||
{
|
||||
Title = "GTA:V ControlPanl DataService",
|
||||
Version = "0.1",
|
||||
@@ -91,22 +90,33 @@ namespace ReallifeGamemode.DataService
|
||||
|
||||
c.SwaggerDoc("DataService", info);
|
||||
|
||||
c.AddSecurityDefinition("Bearer", new ApiKeyScheme
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Name = "Authorization",
|
||||
In = "Header",
|
||||
Type = "apiKey"
|
||||
In = ParameterLocation.Header,
|
||||
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.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
app.UseAuthentication();
|
||||
|
||||
|
||||
35
ReallifeGamemode.DataService/log4net.config
Normal file
35
ReallifeGamemode.DataService/log4net.config
Normal 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>
|
||||
Reference in New Issue
Block a user