forked from mattwcole/gelf-extensions-logging
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
176 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 5 additions & 12 deletions
17
...Extensions.Logging.Samples.AspNetCore2/Gelf.Extensions.Logging.Samples.AspNetCore2.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
samples/Gelf.Extensions.Logging.Samples.AspNetCore2/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
samples/Gelf.Extensions.Logging.Samples.AspNetCore2/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
16 changes: 5 additions & 11 deletions
16
samples/Gelf.Extensions.Logging.Samples.AspNetCore2/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "*" | ||
} |
45 changes: 0 additions & 45 deletions
45
samples/Gelf.Extensions.Logging.Samples.AspNetCore3/Controllers/ValuesController.cs
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
samples/Gelf.Extensions.Logging.Samples.AspNetCore3/Controllers/WeatherForecastController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} | ||
} | ||
} |
8 changes: 2 additions & 6 deletions
8
...Extensions.Logging.Samples.AspNetCore3/Gelf.Extensions.Logging.Samples.AspNetCore3.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.