|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.IO; |
| 4 | +using System.Linq; |
3 | 5 | using System.Reflection; |
| 6 | +using Coderr.Client.Contracts; |
4 | 7 | using log4net; |
5 | 8 | using log4net.Config; |
6 | 9 |
|
7 | 10 | namespace Coderr.Client.Demo |
8 | 11 | { |
9 | | - |
| 12 | + |
10 | 13 | class Program |
11 | 14 | { |
12 | 15 | static void Main() |
13 | 16 | { |
14 | | - var log = CreateLogger(); |
15 | | - log.Info("Starting application"); |
| 17 | + // This is required to activate Coderr + |
| 18 | + // the nuget package "Coderr.Client" |
| 19 | + var url = new Uri("http://report.coderr.io"); |
16 | 20 |
|
17 | | - var url = new Uri("http://localhost:60473/"); |
| 21 | + // The appKey and sharedSecret can be found in Coderr |
18 | 22 | Err.Configuration.Credentials(url, |
19 | | - "5a617e0773b94284bef33940e4bc8384", |
20 | | - "3fab63fb846c4dd289f67b0b3340fefc"); |
| 23 | + "28b83bdb5e474213922d8fcded2c1d47", |
| 24 | + "351b658e63974ab7bca125b7addd1185"); |
| 25 | + |
| 26 | + // Attach the 100 latest log entries |
| 27 | + // to every error report from log4net |
| 28 | + // |
| 29 | + // Requires the nuget package "Coder.Client.log4net" |
21 | 30 | Err.Configuration.CatchLog4NetExceptions(); |
| 31 | + var updatedUser = new string { }; |
22 | 32 |
|
23 | | - Err.Configuration.AddPartition(x => |
| 33 | + try |
| 34 | + { |
| 35 | + throw new InvalidOperationException("oops, something failed"); |
| 36 | + } |
| 37 | + catch (Exception ex) |
24 | 38 | { |
25 | | - x.AddPartition("ServerId", Environment.MachineName); |
26 | | - }); |
| 39 | + // This is how you manually report errors |
| 40 | + // You can attach any kind of information |
| 41 | + // |
| 42 | + // Escalate the error directly to "important", |
| 43 | + // which means that you get an notification and it's |
| 44 | + // automatically added to your backlog |
| 45 | + Err.Report(ex, new { User = updatedUser, ErrTags = "important,backend" }); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + var log = CreateLogger(); |
| 50 | + log.Info("Starting application"); |
27 | 51 |
|
28 | | - Err.Configuration.EnvironmentName = "Production"; |
| 52 | + //var url = new Uri("http://localhost:60473/"); |
| 53 | + //Err.Configuration.Credentials(url, |
| 54 | + // "5a617e0773b94284bef33940e4bc8384", |
| 55 | + // "3fab63fb846c4dd289f67b0b3340fefc"); |
| 56 | + url = new Uri("http://adhost:81/"); |
| 57 | + Err.Configuration.Credentials(url, |
| 58 | + "28b83bdb5e474213922d8fcded2c1d47", |
| 59 | + "351b658e63974ab7bca125b7addd1185"); |
| 60 | + Err.Configuration.CatchLog4NetExceptions(); |
29 | 61 |
|
30 | 62 | try |
31 | 63 | { |
32 | | - log.Debug("Calling hello"); |
33 | | - throw new InvalidDataException("Hello, this is an long example exception"); |
| 64 | + Err.Configuration.AddPartition(x => { x.AddPartition("ServerId", Environment.MachineName); }); |
| 65 | + |
| 66 | + Err.Configuration.EnvironmentName = "Production"; |
| 67 | + |
| 68 | + try |
| 69 | + { |
| 70 | + log.Debug("Calling hello"); |
| 71 | + throw new InvalidDataException("Hello, this is an long example exception"); |
| 72 | + } |
| 73 | + catch (Exception ex) |
| 74 | + { |
| 75 | + //log.Error("Opps, failed!", ex); |
| 76 | + //Err.Report(ex, new { userId = 10, ErrTags = "console" }); |
| 77 | + var report = Err.GenerateReport(ex, new { userId = 10, ErrTags = "important" }); |
| 78 | + if (report.LogEntries != null) |
| 79 | + { |
| 80 | + var entries = new List<LogEntryDto>(report.LogEntries) |
| 81 | + { |
| 82 | + new LogEntryDto(DateTime.UtcNow, 1, "This is an test") |
| 83 | + }; |
| 84 | + report.LogEntries = entries.ToArray(); |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + report.LogEntries = new LogEntryDto[] |
| 89 | + { |
| 90 | + new LogEntryDto(DateTime.UtcNow, 1, "This is an test") |
| 91 | + }; |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | + Err.UploadReport(report); |
| 96 | + Console.WriteLine("Report sent"); |
| 97 | + Err.LeaveFeedback(report.ReportId, "[email protected]", "This is what I did: NOTHING!"); |
| 98 | + } |
| 99 | + |
34 | 100 | } |
35 | 101 | catch (Exception ex) |
36 | 102 | { |
37 | | - //log.Error("Opps, failed!", ex); |
38 | | - //Err.Report(ex, new { userId = 10, ErrTags = "console" }); |
39 | | - var report = Err.GenerateReport(ex, new { userId = 10, ErrTags = "important" }); |
40 | | - Err.UploadReport(report); |
41 | | - Err.LeaveFeedback(report.ReportId, "[email protected]", "This is what I did: NOTHING!"); |
| 103 | + Console.WriteLine(ex); |
42 | 104 | } |
43 | 105 |
|
| 106 | + Console.WriteLine("Press ENTER to qiut"); |
| 107 | + Console.ReadLine(); |
44 | 108 | return; |
45 | 109 | Err.ReportLogicError("User should have been assigned.", errorId: "MainN"); |
46 | 110 |
|
|
0 commit comments