-
Notifications
You must be signed in to change notification settings - Fork 42
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
14 changed files
with
235 additions
and
45 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
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
31 changes: 31 additions & 0 deletions
31
samples/Gelf.Extensions.Logging.Samples.AspNetCore2/Controllers/ValuesController.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,31 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Gelf.Extensions.Logging.Samples.AspNetCore2.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ValuesController : Controller | ||
{ | ||
private readonly ILogger<ValuesController> _logger; | ||
|
||
public ValuesController(ILogger<ValuesController> logger) | ||
{ | ||
_logger = logger; | ||
_logger.LogDebug("Values controller initialising"); | ||
} | ||
|
||
[HttpGet] | ||
public IEnumerable<string> Get() | ||
{ | ||
using (_logger.BeginScope(("method_name", nameof(Get)))) | ||
{ | ||
var result = new[] {"foo", "bar"}; | ||
|
||
_logger.LogInformation("Returning {value1} and {value2} from controller", result[0], result[1]); | ||
|
||
return result; | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="wwwroot\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Gelf.Extensions.Logging" Version="1.2.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
38 changes: 38 additions & 0 deletions
38
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Gelf.Extensions.Logging.Samples.AspNetCore2 | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
BuildWebHost(args).Run(); | ||
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) | ||
{ | ||
return WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.ConfigureLogging((context, builder) => | ||
{ | ||
// Read GelfLoggerOptions from appsettings.json. | ||
builder.Services.Configure<GelfLoggerOptions>(context.Configuration.GetSection("Graylog")); | ||
|
||
// Optionally configure GelfLoggerOptions further. | ||
builder.Services.PostConfigure<GelfLoggerOptions>(options => | ||
options.AdditionalFields["machine_name"] = Environment.MachineName); | ||
|
||
// Read Logging settings from appsettings.json and add providers. | ||
builder.AddConfiguration(context.Configuration.GetSection("Logging")) | ||
.AddConsole() | ||
.AddDebug() | ||
.AddGelf(); | ||
}) | ||
.Build(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
samples/Gelf.Extensions.Logging.Samples.AspNetCore2/Properties/launchSettings.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,29 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:50718/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"Gelf.Extensions.Logging.Samples.AspNetCore2": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "api/values", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:50719/" | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
samples/Gelf.Extensions.Logging.Samples.AspNetCore2/Startup.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,32 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Gelf.Extensions.Logging.Samples.AspNetCore2 | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddMvc(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseMvc(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Information" | ||
}, | ||
"Console": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor.Internal": "Warning", | ||
"Microsoft.AspNetCore.Mvc.Razor.Razor": "Debug", | ||
"Microsoft.AspNetCore.Mvc.Razor": "Error" | ||
} | ||
}, | ||
"GELF": { | ||
"IncludeScopes": true, | ||
"LogLevel": { | ||
"Default": "Debug" | ||
} | ||
} | ||
}, | ||
"Graylog": { | ||
"Host": "localhost", | ||
"Port": 12201, | ||
"LogSource": "console-app-3" | ||
} | ||
} |
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
24 changes: 12 additions & 12 deletions
24
samples/Gelf.Extensions.Logging.Samples.NetCore1/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,15 +1,15 @@ | ||
{ | ||
"Logging": { | ||
"Console": { | ||
"LogLevel": { | ||
"Default": "Debug" | ||
} | ||
}, | ||
"Graylog": { | ||
"Host": "localhost", | ||
"Port": 12201, | ||
"LogSource": "console-app-1", | ||
"LogLevel": "Trace" | ||
} | ||
"Logging": { | ||
"Console": { | ||
"LogLevel": { | ||
"Default": "Debug" | ||
} | ||
}, | ||
"Graylog": { | ||
"Host": "localhost", | ||
"Port": 12201, | ||
"LogSource": "console-app-1", | ||
"LogLevel": "Trace" | ||
} | ||
} | ||
} |
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
44 changes: 22 additions & 22 deletions
44
samples/Gelf.Extensions.Logging.Samples.NetCore2/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,25 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor.Razor": "Debug", | ||
"Default": "Information" | ||
}, | ||
"Console": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor.Internal": "Warning", | ||
"Default": "Debug" | ||
} | ||
}, | ||
"GELF": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor": "Error", | ||
"Default": "Trace" | ||
} | ||
} | ||
"Logging": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor.Razor": "Debug", | ||
"Default": "Information" | ||
}, | ||
"Graylog": { | ||
"Host": "localhost", | ||
"Port": 12201, | ||
"LogSource": "console-app-2" | ||
} | ||
"Console": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor.Internal": "Warning", | ||
"Default": "Debug" | ||
} | ||
}, | ||
"GELF": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor": "Error", | ||
"Default": "Trace" | ||
} | ||
} | ||
}, | ||
"Graylog": { | ||
"Host": "localhost", | ||
"Port": 12201, | ||
"LogSource": "console-app-2" | ||
} | ||
} |