mirror of
https://github.com/yaakov-h/Notepad.Extensions.Logging.git
synced 2025-04-19 02:35:12 +00:00
Initial version
This commit is contained in:
commit
aecb3421c7
9 changed files with 257 additions and 0 deletions
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Notepad.Extensions.Logging\Notepad.Extensions.Logging.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
38
Notepad.Extensions.Logging.FunctionalTest/Program.cs
Normal file
38
Notepad.Extensions.Logging.FunctionalTest/Program.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Notepad.Extensions.Logging.FunctionalTest
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var sc = new ServiceCollection();
|
||||
sc.AddLogging(lb =>
|
||||
{
|
||||
lb.AddConsole();
|
||||
lb.AddNotepad();
|
||||
});
|
||||
|
||||
var sp = sc.BuildServiceProvider();
|
||||
var logger = sp.GetRequiredService<ILogger<Program>>();
|
||||
|
||||
logger.LogWarning("Here is a warning.");
|
||||
logger.LogError(GetException(), "oh no!.");
|
||||
logger.LogInformation("Here is some info.");
|
||||
}
|
||||
|
||||
static Exception GetException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new InvalidOperationException("Wheeeeeeee");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue