Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
120 lines (99 loc) · 4.2 KB

File metadata and controls

120 lines (99 loc) · 4.2 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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 Newtonsoft.Json.Linq;
using NLog;
using NLog.Config;
using StackifyLib;
using static System.Net.WebRequestMethods;
namespace CoreConsoleApp
{
public class Program
{
static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory());
//.AddJsonFile("Stackify.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;
//Config.ReadStackifyJSONConfig();
//NLogTest();
Console.WriteLine($"Stackify Config AppName: {StackifyLib.Config.AppName}");
Console.WriteLine($"Stackify Config EnvironmentName: {StackifyLib.Config.Environment}");
Console.WriteLine($"Stackify Config ApiKey: {StackifyLib.Config.ApiKey}");
StackifyLib.ProfileTracer.SetApplicationName("Test Name 2");
StackifyLib.ProfileTracer.SetEnvironmentName("Test Environment 2");
var tracer = StackifyLib.ProfileTracer.CreateAsOperation("Operation Name", Trace.CorrelationManager.ActivityId.ToString());
tracer.Exec(() => //FYI, async code is also supported via tracer.ExecAsync()
{
//Do some stuff here
Task.Delay(1000).GetAwaiter().GetResult();
Console.WriteLine($"StackifyLib Operation");
});
StackifyLib.ProfileTracer.SetApplicationName("Test Name 3");
StackifyLib.ProfileTracer.SetEnvironmentName("Test Environment 3");
TestInstrument();
StackifyLib.Logger.Shutdown(); //best practice for console apps
Console.ReadLine();
}
private static void TestInstrument()
{
Task.Delay(1000).GetAwaiter().GetResult();
Console.WriteLine($"Custom Operation");
TestInstrumentNested();
}
private static void TestInstrumentNested()
{
Task.Delay(1000).GetAwaiter().GetResult();
Console.WriteLine($"Custom Operation Nested");
}
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);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.