-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
46 lines (37 loc) · 1.44 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Text;
using Serilog;
namespace SANDBOX
{
class Program
{
private static readonly StringBuilder _logEventBuffer = new StringBuilder();
static void Main(string[] args)
{
try
{
Log.Logger = new LoggerConfiguration()
// Using a delegate to buffer log messages
.WriteTo.DelegatingTextSink(w => WriteToBuffer(w), outputTemplate:"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
Log.Information("Hello from the sandbox");
Log.Warning("Sample warning");
Log.Error("Sample error");
Log.Error(new Exception("A sample exception"), "Sample error with exception");
Log.CloseAndFlush();
Console.WriteLine("This was logged:");
Console.WriteLine(_logEventBuffer.ToString());
}
catch(Exception ex)
{
Console.WriteLine("{1} while testing{0}{2}", Environment.NewLine, ex.GetType().FullName, ex.Message);
}
Console.WriteLine("Press ENTER to exit");
Console.ReadLine();
}
private static void WriteToBuffer(string formattedLogMessage)
{
_logEventBuffer.AppendLine(formattedLogMessage.TrimEnd(Environment.NewLine.ToCharArray()));
}
}
}