Skip to content

Commit ce018f2

Browse files
author
Jonas Gauffin
committed
Bugfix for UserToken
1 parent 66ffb9c commit ce018f2

File tree

5 files changed

+100
-27
lines changed

5 files changed

+100
-27
lines changed

src/Coderr.Client.Demo/Coderr.Client.Demo.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<TargetFrameworks>netcoreapp3.1;net461</TargetFrameworks>
66
<Version>1.1.0.0</Version>
77
</PropertyGroup>
88

src/Coderr.Client.Demo/Program.cs

+81-17
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,110 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Linq;
35
using System.Reflection;
6+
using Coderr.Client.Contracts;
47
using log4net;
58
using log4net.Config;
69

710
namespace Coderr.Client.Demo
811
{
9-
12+
1013
class Program
1114
{
1215
static void Main()
1316
{
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");
1620

17-
var url = new Uri("http://localhost:60473/");
21+
// The appKey and sharedSecret can be found in Coderr
1822
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"
2130
Err.Configuration.CatchLog4NetExceptions();
31+
var updatedUser = new string { };
2232

23-
Err.Configuration.AddPartition(x =>
33+
try
34+
{
35+
throw new InvalidOperationException("oops, something failed");
36+
}
37+
catch (Exception ex)
2438
{
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");
2751

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();
2961

3062
try
3163
{
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+
34100
}
35101
catch (Exception ex)
36102
{
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);
42104
}
43105

106+
Console.WriteLine("Press ENTER to qiut");
107+
Console.ReadLine();
44108
return;
45109
Err.ReportLogicError("User should have been assigned.", errorId: "MainN");
46110

src/Coderr.Client/Coderr.Client.csproj

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@
66
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Coderr.Client.xml</DocumentationFile>
77
<RootNamespace>Coderr.Client</RootNamespace>
88

9-
<PackageReleaseNotes>Resharper cleanup removed private setters.</PackageReleaseNotes>
10-
<Version>2.0.5</Version>
9+
<PackageReleaseNotes>Bugfix for UserToken.</PackageReleaseNotes>
10+
<Version>2.0.6</Version>
1111
</PropertyGroup>
1212

1313
<PropertyGroup>
1414
<PackageId>Coderr.Client</PackageId>
1515
<Authors>Coderr AB</Authors>
1616
<Description>Automated exception handling for .NET based applications</Description>
1717
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
18-
<Copyright>Copyright 2020 © Coderr AB. All rights reserved.</Copyright>
18+
<Copyright>Copyright 2022 © Coderr AB. All rights reserved.</Copyright>
1919
<PackageTags>logger exceptions analysis .net-core NetStandard</PackageTags>
2020
<RepositoryUrl>https://github.com/coderrio/coderr.client</RepositoryUrl>
21-
<PackageIcon>NugetIcon.png</PackageIcon>
22-
<PackageIconUrl>https://coderr.io/images/nuget_icon.png</PackageIconUrl>
21+
<PackageIcon>NugetIcon.png</PackageIcon>
22+
<PackageIconUrl>https://coderr.io/images/nuget_icon.png</PackageIconUrl>
2323
<RepositoryType>git</RepositoryType>
2424
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
2525
<PackageProjectUrl>https://coderr.io</PackageProjectUrl>
26+
<UserSecretsId>36db3a4e-b04d-4f4f-9fd8-0dbbba237f6f</UserSecretsId>
2627
</PropertyGroup>
2728

2829
<ItemGroup>
2930
<Content Include="README.txt">
3031
<Pack>true</Pack>
3132
<PackagePath>README.txt</PackagePath>
3233
</Content>
33-
<None Include="NugetIcon.png" Pack="true" PackagePath="/" />
34+
<None Include="NugetIcon.png" Pack="true" PackagePath="/" />
3435
</ItemGroup>
3536

3637
<ItemGroup>

src/Coderr.Client/ContextCollections/Providers/UserCredentials.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
4-
using System.Security.Cryptography;
54
using System.Security.Principal;
65
using System.Text;
76
using Coderr.Client.Contracts;
@@ -36,7 +35,12 @@ public UserCredentials(IIdentity identity) : base("UserCredentials")
3635
if (string.IsNullOrEmpty(identity.Name))
3736
Properties.Add("UserName", "[Anonynmous]");
3837
else
39-
SplitAccountName(identity.Name);
38+
{
39+
var pair = SplitAccountName(identity.Name);
40+
DomainName = pair.Item1;
41+
UserName = pair.Item2;
42+
}
43+
4044
}
4145

4246
/// <summary>
@@ -56,7 +60,9 @@ public UserCredentials(string domainName, string userName) : base("UserCredentia
5660
/// <param name="userName">User name without domain (i.e. should not include "domainName\")</param>
5761
public UserCredentials(string userName) : base("UserCredentials")
5862
{
59-
SplitAccountName(userName);
63+
var pair = SplitAccountName(userName);
64+
DomainName = pair.Item1;
65+
UserName = pair.Item2;
6066
}
6167

6268
/// <summary>

src/Coderr.Client/Uploaders/UploadToCoderr.cs

+2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,13 @@ private async Task PostData(string uri, object dto)
190190
try
191191
{
192192
var response = await _uploadFunc(msg).ConfigureAwait(false);
193+
Console.WriteLine("Successs" + response.StatusCode + " " + response.ReasonPhrase);
193194
if (!response.IsSuccessStatusCode)
194195
ProcessResponseError(response);
195196
}
196197
catch (Exception ex)
197198
{
199+
Console.WriteLine("FAILED! " + ex);
198200
OnUploadFailed(this, new UploadReportFailedEventArgs(ex, dto));
199201
if (_throwExceptionsAccessor() || _queueReportsAccessor())
200202
throw;

0 commit comments

Comments
 (0)