mirror of
https://github.com/yaakov-h/Notepad.Extensions.Logging.git
synced 2024-10-16 18:10:02 +00:00
39 lines
966 B
C#
39 lines
966 B
C#
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|