-
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
7 changed files
with
181 additions
and
1 deletion.
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
17 changes: 17 additions & 0 deletions
17
.../Gelf.Extensions.Logging.Samples.NetCore1/Gelf.Extensions.Logging.Samples.NetCore1.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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Gelf.Extensions.Logging" Version="1.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
47 changes: 47 additions & 0 deletions
47
samples/Gelf.Extensions.Logging.Samples.NetCore1/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,47 @@ | ||
using System; | ||
using System.IO; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Gelf.Extensions.Logging.Samples.NetCore1 | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
|
||
var serviceProvider = new ServiceCollection() | ||
.AddLogging() | ||
.BuildServiceProvider(); | ||
|
||
try | ||
{ | ||
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>(); | ||
loggerFactory | ||
.AddConsole(configuration.GetSection("Logging:Console")) | ||
.AddGelf(configuration.GetSection("Logging:GELF").Get<GelfLoggerOptions>()); | ||
|
||
var logger = serviceProvider.GetRequiredService<ILogger<Program>>(); | ||
|
||
logger.LogInformation("Information level log from netcoreapp1.1"); | ||
logger.LogDebug("Debug level log from netcoreapp1.1"); | ||
logger.LogTrace("Trace level log from netcoreapp1.1"); | ||
|
||
using (logger.BeginScope(("custom_attribute", "12345"))) | ||
{ | ||
logger.LogInformation("Log with custom attribute from netcoreapp1.1"); | ||
} | ||
} | ||
finally | ||
{ | ||
// The LoggerFactory must be disposed before the program exits to ensure all queued messages are sent. | ||
(serviceProvider as IDisposable)?.Dispose(); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"Logging": { | ||
"Console": { | ||
"LogLevel": { | ||
"Default": "Debug" | ||
} | ||
}, | ||
"GELF": { | ||
"Host": "localhost", | ||
"Port": 12201, | ||
"LogSource": "console-app-1", | ||
"LogLevel": "Trace" | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../Gelf.Extensions.Logging.Samples.NetCore2/Gelf.Extensions.Logging.Samples.NetCore2.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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Gelf.Extensions.Logging\Gelf.Extensions.Logging.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
40 changes: 40 additions & 0 deletions
40
samples/Gelf.Extensions.Logging.Samples.NetCore2/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,40 @@ | ||
using System.IO; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Gelf.Extensions.Logging.Samples.NetCore2 | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
|
||
var serviceCollection = new ServiceCollection() | ||
.Configure<GelfLoggerOptions>(configuration.GetSection("Logging:GELF")) | ||
.AddLogging(loggingBuilder => loggingBuilder | ||
.AddConfiguration(configuration.GetSection("Logging")) | ||
.AddConsole() | ||
.AddGelf()); | ||
|
||
// The LoggerFactory must be disposed before the program exits to ensure all queued messages are sent. | ||
using (var serviceProvider = serviceCollection.BuildServiceProvider()) | ||
{ | ||
var logger = serviceProvider.GetRequiredService<ILogger<Program>>(); | ||
|
||
logger.LogInformation("Information level log from netcoreapp2.0"); | ||
logger.LogDebug("Debug level log from netcoreapp2.0"); | ||
logger.LogTrace("Trace level log from netcoreapp2.0"); | ||
|
||
using (logger.BeginScope(("custom_attribute", "12345"))) | ||
{ | ||
logger.LogInformation("Log with custom attribute from netcoreapp2.0"); | ||
} | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor.Razor": "Debug", | ||
"Default": "Information" | ||
}, | ||
"Console": { | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor.Internal": "Warning", | ||
"Default": "Debug" | ||
} | ||
}, | ||
"GELF": { | ||
"Host": "localhost", | ||
"Port": 12201, | ||
"LogSource": "console-app-2", | ||
"LogLevel": { | ||
"Microsoft.AspNetCore.Mvc.Razor": "Error", | ||
"Default": "Trace" | ||
} | ||
} | ||
} | ||
} |