-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (43 loc) · 1.56 KB
/
Copy pathProgram.cs
File metadata and controls
52 lines (43 loc) · 1.56 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
using System.Security.Principal;
using log4net;
using log4net.Config;
[assembly: XmlConfigurator(Watch = true)]
internal class Program
{
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
private static void Main()
{
#if NETFRAMEWORK
// Set the user running the process the current principal
// Appender was configured to send the user with the event
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
#endif
// The following anonymous object gets serialized and sent with log messages
ThreadContext.Properties["inventory"] = new
{
SmallPotion = 3,
BigPotion = 0,
CheeseWheels = 512
};
// app.config enables SentryAppender only for level INFO or higher so the Debug
// Does not result in an event in Sentry
Log.Debug("Debug message which is not sent.");
// app.config sets MinimumEventLevel to ERROR, so every below that level is added as a breadcrumb.
Log.Info("Info message which is added as a breadcrumb.");
Log.Error("Error message which is sent as an event.");
try
{
DoWork();
}
catch (Exception e)
{
e.Data.Add("details", "Do work always throws.");
Log.Error("Error: with exception", e);
}
}
private static void DoWork()
{
Log.InfoFormat("InfoFormat: About to throw {0} type of exception.", nameof(NotImplementedException));
throw new NotImplementedException();
}
}