Skip to content

Commit

Permalink
Add sample projects - fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwcole committed Sep 17, 2017
1 parent 84561c2 commit 1a7fe9a
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Gelf.Extensions.Logging.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
VisualStudioVersion = 15.0.26730.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8D2DBBD0-2141-4B3D-BEA5-5FF4B15F0919}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -22,6 +22,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7999DEB6-1
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gelf.Extensions.Logging.Tests", "test\Gelf.Extensions.Logging.Tests\Gelf.Extensions.Logging.Tests.csproj", "{4B299C4A-3A24-47B3-83D1-251D5FBDA174}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{7D9416E1-13A5-4A86-A3F1-2289369D7193}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gelf.Extensions.Logging.Samples.NetCore2", "samples\Gelf.Extensions.Logging.Samples.NetCore2\Gelf.Extensions.Logging.Samples.NetCore2.csproj", "{0A2D1AF3-16F9-4081-A3BE-35331BEF58B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gelf.Extensions.Logging.Samples.NetCore1", "samples\Gelf.Extensions.Logging.Samples.NetCore1\Gelf.Extensions.Logging.Samples.NetCore1.csproj", "{C55B368D-E4C1-42D0-97C2-4AD2F443743B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,12 +42,25 @@ Global
{4B299C4A-3A24-47B3-83D1-251D5FBDA174}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B299C4A-3A24-47B3-83D1-251D5FBDA174}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B299C4A-3A24-47B3-83D1-251D5FBDA174}.Release|Any CPU.Build.0 = Release|Any CPU
{0A2D1AF3-16F9-4081-A3BE-35331BEF58B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A2D1AF3-16F9-4081-A3BE-35331BEF58B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A2D1AF3-16F9-4081-A3BE-35331BEF58B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A2D1AF3-16F9-4081-A3BE-35331BEF58B5}.Release|Any CPU.Build.0 = Release|Any CPU
{C55B368D-E4C1-42D0-97C2-4AD2F443743B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0480562A-97F5-423B-A11F-BD788D04E3AD} = {A6D95AC6-FD7C-459C-ADBE-5797A0EDF123}
{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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6D74A71-1746-4865-AAE2-77625B3E8935}
EndGlobalSection
EndGlobal
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 samples/Gelf.Extensions.Logging.Samples.NetCore1/Program.cs
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 samples/Gelf.Extensions.Logging.Samples.NetCore1/appsettings.json
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"
}
}
}
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 samples/Gelf.Extensions.Logging.Samples.NetCore2/Program.cs
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 samples/Gelf.Extensions.Logging.Samples.NetCore2/appsettings.json
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"
}
}
}
}

0 comments on commit 1a7fe9a

Please sign in to comment.