Skip to content

Commit

Permalink
Update sample apps
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwcole committed Nov 16, 2019
1 parent a8595bf commit 9419d8f
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 205 deletions.
26 changes: 13 additions & 13 deletions Gelf.Extensions.Logging.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
docker-compose.ci.build.yml = docker-compose.ci.build.yml
docker-compose.ci.publish.yml = docker-compose.ci.publish.yml
docker-compose.yml = docker-compose.yml
icon.png = icon.png
LICENSE.md = LICENSE.md
README.md = README.md
icon.png = icon.png
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A6D95AC6-FD7C-459C-ADBE-5797A0EDF123}"
Expand All @@ -30,9 +30,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("{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}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gelf.Extensions.Logging.Samples.AspNetCore3", "samples\Gelf.Extensions.Logging.Samples.AspNetCore3\Gelf.Extensions.Logging.Samples.AspNetCore3.csproj", "{7599B625-DD65-4B68-ACF3-6E9400C0A99B}"
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}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gelf.Extensions.Logging.Samples.AspNetCore2", "samples\Gelf.Extensions.Logging.Samples.AspNetCore2\Gelf.Extensions.Logging.Samples.AspNetCore2.csproj", "{C3D38DAC-25E5-4590-A47D-08A97520C4CB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -56,14 +56,14 @@ Global
{C55B368D-E4C1-42D0-97C2-4AD2F443743B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C55B368D-E4C1-42D0-97C2-4AD2F443743B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C55B368D-E4C1-42D0-97C2-4AD2F443743B}.Release|Any CPU.Build.0 = Release|Any CPU
{1499E4E4-EF81-4309-A664-8FEC115B5C82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
{7599B625-DD65-4B68-ACF3-6E9400C0A99B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7599B625-DD65-4B68-ACF3-6E9400C0A99B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7599B625-DD65-4B68-ACF3-6E9400C0A99B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7599B625-DD65-4B68-ACF3-6E9400C0A99B}.Release|Any CPU.Build.0 = Release|Any CPU
{C3D38DAC-25E5-4590-A47D-08A97520C4CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3D38DAC-25E5-4590-A47D-08A97520C4CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3D38DAC-25E5-4590-A47D-08A97520C4CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3D38DAC-25E5-4590-A47D-08A97520C4CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -73,8 +73,8 @@ Global
{4B299C4A-3A24-47B3-83D1-251D5FBDA174} = {7999DEB6-1492-41CF-A94C-63606C616565}
{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}
{7599B625-DD65-4B68-ACF3-6E9400C0A99B} = {7D9416E1-13A5-4A86-A3F1-2289369D7193}
{C3D38DAC-25E5-4590-A47D-08A97520C4CB} = {7D9416E1-13A5-4A86-A3F1-2289369D7193}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6D74A71-1746-4865-AAE2-77625B3E8935}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,44 @@
namespace Gelf.Extensions.Logging.Samples.AspNetCore2.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
[ApiController]
public class ValuesController : ControllerBase
{
private readonly ILogger<ValuesController> _logger;

public ValuesController(ILogger<ValuesController> logger)
{
_logger = logger;
_logger.LogDebug("Values controller initialising");
}

[HttpGet]
public IEnumerable<string> Get()
public ActionResult<IEnumerable<string>> Get()
{
using (_logger.BeginScope(("scope_field", "foo")))
{
var result = new[] {"bar", "baz"};
var values = new[] { "value1", "value2" };
_logger.LogDebug("Getting {values_count} values", values.Length);
return values;
}

[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
_logger.LogInformation($"Getting value with ID: {id}");
return "value";
}

[HttpPost]
public void Post([FromBody] string value)
{
}

_logger.LogTrace("Returning {value1} and {value2} from controller", result[0], result[1]);
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}

return result;
}
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Gelf.Extensions.Logging" Version="1.5.0-pre1" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
<PackageReference Include="Gelf.Extensions.Logging" Version="2.0.0-pre2" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>

</Project>
36 changes: 12 additions & 24 deletions samples/Gelf.Extensions.Logging.Samples.AspNetCore2/Program.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;

namespace Gelf.Extensions.Logging.Samples.AspNetCore2
{
public class Program
{
public static Task Main(string[] args)
public static void Main(string[] args)
{
return BuildWebHost(args).RunAsync();
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.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;
});
})
.Build();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging((context, builder) => builder.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;
}));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50718/",
"applicationUrl": "http://localhost:57560",
"sslPort": 0
}
},
Expand All @@ -20,10 +21,10 @@
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:50719/"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -16,7 +17,7 @@ public Startup(IConfiguration configuration)

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
{
{
"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"
"foo": "bar"
},
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Gelf.Extensions.Logging.Samples.AspNetCore2.Controllers": "Debug"
}
}
}
},
"AllowedHosts": "*"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace Gelf.Extensions.Logging.Samples.AspNetCore3.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries =
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
_logger.LogInformation("Generating weather forecast");

var random = new Random();

return Enumerable.Range(1, 5).Select(index =>
{
var weatherForecast = new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = random.Next(-20, 55),
Summary = Summaries[random.Next(Summaries.Length)]
};

_logger.LogDebug("Weather will be {weather_summary} on {weather_date}", weatherForecast.Summary, weatherForecast.Date);

return weatherForecast;
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<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" />
<PackageReference Include="Gelf.Extensions.Logging" Version="2.0.0-pre2" />
</ItemGroup>

</Project>
Loading

0 comments on commit 9419d8f

Please sign in to comment.