-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cs
More file actions
43 lines (38 loc) · 1.52 KB
/
Logger.cs
File metadata and controls
43 lines (38 loc) · 1.52 KB
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
using System.Runtime.InteropServices;
using Microsoft.Extensions.Logging;
using SelloutReportingService.Services;
namespace SelloutReportingService
{
/// <summary>
/// Static class holding the default logger instance.
/// </summary>
public static class Logger
{
/// <summary>
/// Our default <see cref="ILogger" /> instance.
/// </summary>
/// <remarks>
/// This instance logs to console and Windows Event Log if running under Windows.
/// </remarks>
public static readonly ILogger Instance = LoggerFactory
.Create(configure =>
{
configure
.AddConsole(o => { o.TimestampFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK"; })
.AddConfiguration(Configuration.Instance);
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return;
const string logName = "Application";
const string sourceName = "SelloutReportingService";
if (!System.Diagnostics.EventLog.SourceExists(sourceName))
{
System.Diagnostics.EventLog.CreateEventSource(sourceName, logName);
}
configure.AddEventLog(settings =>
{
settings.LogName = logName;
settings.SourceName = sourceName;
});
})
.CreateLogger<ReportingServiceControl>();
}
}