Navigation Menu

Skip to content

Commit

Permalink
.NET Core 3.0 Compability.
Browse files Browse the repository at this point in the history
Due to braking changes in Microsoft.Extensions.Logging library, FormattedLogValues is now marked as internal. Therefore, it is changed to IEnumerable<KeyValuePair<string, object>> to make the library compatible with .NET Core 3.0 version.
  • Loading branch information
Namık Barış İdil committed Apr 24, 2019
1 parent 5391521 commit cc57636
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 5 deletions.
13 changes: 10 additions & 3 deletions Gelf.Extensions.Logging.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.15
# Visual Studio Version 16
VisualStudioVersion = 16.0.28822.285
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8D2DBBD0-2141-4B3D-BEA5-5FF4B15F0919}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -29,7 +29,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gelf.Extensions.Logging.Sam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gelf.Extensions.Logging.Samples.NetCore1", "samples\Gelf.Extensions.Logging.Samples.NetCore1\Gelf.Extensions.Logging.Samples.NetCore1.csproj", "{C55B368D-E4C1-42D0-97C2-4AD2F443743B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gelf.Extensions.Logging.Samples.AspNetCore2", "samples\Gelf.Extensions.Logging.Samples.AspNetCore2\Gelf.Extensions.Logging.Samples.AspNetCore2.csproj", "{1499E4E4-EF81-4309-A664-8FEC115B5C82}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gelf.Extensions.Logging.Samples.AspNetCore2", "samples\Gelf.Extensions.Logging.Samples.AspNetCore2\Gelf.Extensions.Logging.Samples.AspNetCore2.csproj", "{1499E4E4-EF81-4309-A664-8FEC115B5C82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gelf.Extensions.Logging.Samples.AspNetCore3", "samples\Gelf.Extensions.Logging.Samples.AspNetCore3\Gelf.Extensions.Logging.Samples.AspNetCore3.csproj", "{208400F6-FCA1-4C01-BD0B-EF148772633D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -57,6 +59,10 @@ Global
{1499E4E4-EF81-4309-A664-8FEC115B5C82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1499E4E4-EF81-4309-A664-8FEC115B5C82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1499E4E4-EF81-4309-A664-8FEC115B5C82}.Release|Any CPU.Build.0 = Release|Any CPU
{208400F6-FCA1-4C01-BD0B-EF148772633D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{208400F6-FCA1-4C01-BD0B-EF148772633D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{208400F6-FCA1-4C01-BD0B-EF148772633D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{208400F6-FCA1-4C01-BD0B-EF148772633D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -67,6 +73,7 @@ Global
{0A2D1AF3-16F9-4081-A3BE-35331BEF58B5} = {7D9416E1-13A5-4A86-A3F1-2289369D7193}
{C55B368D-E4C1-42D0-97C2-4AD2F443743B} = {7D9416E1-13A5-4A86-A3F1-2289369D7193}
{1499E4E4-EF81-4309-A664-8FEC115B5C82} = {7D9416E1-13A5-4A86-A3F1-2289369D7193}
{208400F6-FCA1-4C01-BD0B-EF148772633D} = {7D9416E1-13A5-4A86-A3F1-2289369D7193}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6D74A71-1746-4865-AAE2-77625B3E8935}
Expand Down
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace Gelf.Extensions.Logging.Samples.AspNetCore3.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}

// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}

// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}

// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}

// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Gelf.Extensions.Logging\Gelf.Extensions.Logging.csproj" />
</ItemGroup>

</Project>
40 changes: 40 additions & 0 deletions samples/Gelf.Extensions.Logging.Samples.AspNetCore3/Program.cs
@@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Reflection;

namespace Gelf.Extensions.Logging.Samples.AspNetCore3
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, builder) =>
{
builder.AddConfiguration(context.Configuration.GetSection("Logging"))
.AddConsole()
.AddDebug()
.AddGelf(options =>
{
// Optional config combined with Logging:GELF configuration section.
options.LogSource = context.HostingEnvironment.ApplicationName;
options.AdditionalFields["machine_name"] = Environment.MachineName;
options.AdditionalFields["app_version"] = Assembly.GetEntryAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
});
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
}
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50420",
"sslPort": 44356
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Gelf.Extensions.Logging.Samples.AspNetCore3": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
57 changes: 57 additions & 0 deletions samples/Gelf.Extensions.Logging.Samples.AspNetCore3/Startup.cs
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Gelf.Extensions.Logging.Samples.AspNetCore3
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers()
.AddNewtonsoftJson();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
@@ -0,0 +1,25 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
},
"Console": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore.Mvc.Razor.Internal": "Warning",
"Microsoft.AspNetCore.Mvc.Razor.Razor": "Debug",
"Microsoft.AspNetCore.Mvc.Razor": "Error"
}
},
"GELF": {
"Host": "localhost",
"AdditionalFields": {
"project_name": "my-project"
},
"LogLevel": {
"Default": "Information",
"Gelf.Extensions.Logging.Samples.AspNetCore2.Controllers": "Debug"
}
}
}
}
4 changes: 2 additions & 2 deletions src/Gelf.Extensions.Logging/GelfLogger.cs
Expand Up @@ -113,8 +113,8 @@ public IDisposable BeginScope<TState>(TState state)

private static IEnumerable<KeyValuePair<string, object>> GetStateAdditionalFields<TState>(TState state)
{
return state is FormattedLogValues logValues
? logValues.Take(logValues.Count - 1)
return state is /*FormattedLogValues*/IEnumerable<KeyValuePair<string, object>> logValues
? logValues.Take(logValues.Count() - 1)
: Enumerable.Empty<KeyValuePair<string, object>>();
}

Expand Down

0 comments on commit cc57636

Please sign in to comment.