forked from stackify/stackify-api-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (69 loc) · 2.66 KB
/
Program.cs
File metadata and controls
85 lines (69 loc) · 2.66 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Xml;
using log4net.Config;
using log4net.Repository;
using Microsoft.Extensions.Configuration;
using NLog;
using NLog.Config;
using StackifyLib;
namespace CoreConsoleApp
{
public class Program
{
static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
var config = builder.Build();
config.ConfigureStackifyLogging();
// OR
//StackifyLib.Config.SetConfiguration(config);
//enable debug logging
StackifyLib.Utils.StackifyAPILogger.OnLogMessage += StackifyAPILogger_OnLogMessage;
StackifyLib.Utils.StackifyAPILogger.LogEnabled = true;
//NLogTest();
StackifyLib.Logger.Shutdown(); //best practice for console apps
}
private static void NLogTest()
{
var path = Path.Combine(Directory.GetCurrentDirectory(), "nlog.config");
NLog.LogManager.Configuration = new XmlLoggingConfiguration(path, true);
NLog.Logger nlog = LogManager.GetCurrentClassLogger();
for (int i = 0; i < 100; i++)
{
// StackifyLib.Logger.Queue("Debug", "Test message");
//System.Threading.Thread.Sleep(1);
nlog.Debug("Hello");
//nlog.Debug(new { color = "red", int1 = 1 });
}
}
private static void Log4NetTest()
{
XmlDocument log4netConfig = new XmlDocument();
using (StreamReader reader = new StreamReader(new FileStream("log4net.config", FileMode.Open, FileAccess.Read)))
{
log4netConfig.Load(reader);
}
ILoggerRepository rep = log4net.LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
XmlConfigurator.Configure(rep, log4netConfig["log4net"]);
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
for (int i = 0; i < 100; i++)
{
// StackifyLib.Logger.Queue("Debug", "Test message");
//System.Threading.Thread.Sleep(1);
log.Debug(new { color = "red", int1 = 1 });
}
}
private static void StackifyAPILogger_OnLogMessage(string data)
{
Debug.WriteLine(data);
}
}
}