Skip to content

Commit 7f24f0f

Browse files
author
Jonas Gauffin
committed
Added support for log files
1 parent 2ef33c3 commit 7f24f0f

File tree

27 files changed

+484
-16
lines changed

27 files changed

+484
-16
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
using System.Text;
5+
6+
namespace Coderr.Server.Abstractions
7+
{
8+
/// <summary>
9+
/// Extensions for IPAddress.
10+
/// </summary>
11+
public static class IpAddressExtensions
12+
{
13+
/// <summary>
14+
/// An extension method to determine if an IP address is internal, as specified in RFC1918
15+
/// </summary>
16+
/// <param name="toTest">The IP address that will be tested</param>
17+
/// <returns>Returns true if the IP is internal, false if it is external</returns>
18+
public static bool IsInternal(this IPAddress toTest)
19+
{
20+
if (IPAddress.IsLoopback(toTest)) return true;
21+
22+
if (toTest.IsIPv6LinkLocal || toTest.IsIPv6SiteLocal)
23+
{
24+
return true;
25+
}
26+
27+
var bytes = toTest.GetAddressBytes();
28+
switch (bytes[0])
29+
{
30+
case 10:
31+
return true;
32+
case 172:
33+
return bytes[1] < 32 && bytes[1] >= 16;
34+
case 192:
35+
return bytes[1] == 168;
36+
default:
37+
return false;
38+
}
39+
}
40+
}
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace Coderr.Server.Api.Modules.Logs.Commands
4+
{
5+
[Command]
6+
public class StoreLogEntries
7+
{
8+
public StoreLogEntries(int incidentId, int reportId, StoreLogEntriesEntry[] entries)
9+
{
10+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
11+
if (reportId <= 0) throw new ArgumentOutOfRangeException(nameof(reportId));
12+
IncidentId = incidentId;
13+
ReportId = reportId;
14+
Entries = entries ?? throw new ArgumentNullException(nameof(entries));
15+
}
16+
17+
protected StoreLogEntries()
18+
{
19+
20+
}
21+
22+
public StoreLogEntriesEntry[] Entries { get; private set; }
23+
public int IncidentId { get; private set; }
24+
public int ReportId { get; private set; }
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace Coderr.Server.Api.Modules.Logs.Commands
4+
{
5+
public class StoreLogEntriesEntry
6+
{
7+
public DateTime TimeStampUtc { get; set; }
8+
9+
public string Message { get; set; }
10+
11+
public StoreLogEntriesLogLevel Level { get; set; }
12+
13+
public string Exception { get; set; }
14+
15+
public string Source { get; set; }
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Coderr.Server.Api.Modules.Logs.Commands
2+
{
3+
public enum StoreLogEntriesLogLevel
4+
{
5+
Trace = 1,
6+
Debug = 2,
7+
Info = 3,
8+
Warning = 4,
9+
Error = 5,
10+
Critical = 6
11+
}
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using DotNetCqs;
3+
4+
namespace Coderr.Server.Api.Modules.Logs.Queries
5+
{
6+
[Message]
7+
public class GetLogs : Query<GetLogsResult>
8+
{
9+
public GetLogs(int incidentId)
10+
{
11+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
12+
IncidentId = incidentId;
13+
}
14+
15+
public GetLogs(int incidentId, int reportId)
16+
{
17+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
18+
if (reportId <= 0) throw new ArgumentOutOfRangeException(nameof(reportId));
19+
IncidentId = incidentId;
20+
ReportId = reportId;
21+
}
22+
23+
protected GetLogs()
24+
{
25+
26+
}
27+
28+
/// <summary>
29+
/// Incident to check.
30+
/// </summary>
31+
public int IncidentId { get; private set; }
32+
33+
/// <summary>
34+
/// Check for a specific report (if set).
35+
/// </summary>
36+
public int? ReportId { get; private set; }
37+
}
38+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Coderr.Server.Api.Modules.Logs.Queries
2+
{
3+
public class GetLogsResult
4+
{
5+
public GetLogsResultEntry[] Entries { get; set; }
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace Coderr.Server.Api.Modules.Logs.Queries
4+
{
5+
public class GetLogsResultEntry
6+
{
7+
public DateTime TimeStampUtc { get; set; }
8+
9+
public string Message { get; set; }
10+
11+
public GetLogsResultEntryLevel Level { get; set; }
12+
13+
public string Exception { get; set; }
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Coderr.Server.Api.Modules.Logs.Queries
2+
{
3+
public enum GetLogsResultEntryLevel
4+
{
5+
Trace = 1,
6+
Debug = 2,
7+
Info = 3,
8+
Warning = 4,
9+
Error = 5,
10+
Critical = 6
11+
}
12+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using DotNetCqs;
3+
4+
namespace Coderr.Server.Api.Modules.Logs.Queries
5+
{
6+
/// <summary>
7+
/// Check if an incident (or a specific report for that incident) has logs attached to it.
8+
/// </summary>
9+
[Message]
10+
public class HasLogs : Query<HasLogsReply>
11+
{
12+
public HasLogs(int incidentId)
13+
{
14+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
15+
IncidentId = incidentId;
16+
}
17+
18+
public HasLogs(int incidentId, int reportId)
19+
{
20+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
21+
if (reportId <= 0) throw new ArgumentOutOfRangeException(nameof(reportId));
22+
IncidentId = incidentId;
23+
ReportId = reportId;
24+
}
25+
26+
protected HasLogs()
27+
{
28+
29+
}
30+
31+
/// <summary>
32+
/// Incident to check.
33+
/// </summary>
34+
public int IncidentId { get; private set; }
35+
36+
/// <summary>
37+
/// Check for a specific report (if set).
38+
/// </summary>
39+
public int? ReportId { get; private set; }
40+
}
41+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Coderr.Server.Api.Modules.Logs.Queries
2+
{
3+
public class HasLogsReply
4+
{
5+
public bool HasLogs { get; set; }
6+
}
7+
}

0 commit comments

Comments
 (0)