Adding logger
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
using log4net;
|
||||
|
||||
namespace MimeSharp;
|
||||
|
||||
public static class DateTimeHelper
|
||||
{
|
||||
private static readonly ILog _logger = LogManager.GetLogger(typeof(DateTimeHelper));
|
||||
|
||||
public static string GetRfc1123()
|
||||
{
|
||||
_logger.Debug("Generating RFC1123 date.");
|
||||
return DateTime.Now.ToString("R");
|
||||
}
|
||||
|
||||
public static string GetRfc3339()
|
||||
{
|
||||
_logger.Debug("Generating RFC3339 date.");
|
||||
return DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MimeSharp;
|
||||
|
||||
public static class Extensions
|
||||
@@ -26,6 +29,11 @@ public static class Extensions
|
||||
{
|
||||
return PreProd.Contains(region);
|
||||
}
|
||||
|
||||
public static string ToJson(this IDictionary dictionary)
|
||||
{
|
||||
return JsonSerializer.Serialize(dictionary);
|
||||
}
|
||||
|
||||
public static void AddRange<T>(this ICollection<T> target, IEnumerable<T> source)
|
||||
{
|
||||
|
||||
+15
-2
@@ -1,8 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using log4net;
|
||||
using MimeSharp.Exceptions;
|
||||
using MimeSharp.WTOs;
|
||||
|
||||
@@ -10,6 +9,7 @@ namespace MimeSharp;
|
||||
|
||||
public class MimeSharp
|
||||
{
|
||||
private static readonly ILog _logger = LogManager.GetLogger(typeof(MimeSharp));
|
||||
private const string HmacSha1Algorithm = "HMACSHA1";
|
||||
private const string XmcReqId = "x-mcm-req-id";
|
||||
private const string XmcDate = "x-mcm-date";
|
||||
@@ -30,6 +30,9 @@ public class MimeSharp
|
||||
public string Username { get; set; }
|
||||
public string AppKey { get; set; }
|
||||
public string AppId { get; set; }
|
||||
|
||||
public string RegionName => _discoveryResponse.region.Name;
|
||||
public string ApiUrl => _discoveryResponse.region.Api;
|
||||
|
||||
private MimecastRegion _region;
|
||||
private LoginResponseWTO _login;
|
||||
@@ -39,6 +42,7 @@ public class MimeSharp
|
||||
|
||||
public static string GetGuid()
|
||||
{
|
||||
_logger.Debug("Generating new GUID,");
|
||||
return Guid.NewGuid().ToString("N");
|
||||
}
|
||||
|
||||
@@ -73,6 +77,10 @@ public class MimeSharp
|
||||
|
||||
_discoveryResponse = discoveryResponse?.Data.First() ??
|
||||
throw new MimecastResponseException("Discovery response was null.");
|
||||
|
||||
_discoveryResponse = discoveryResponse.Data.First();
|
||||
|
||||
_logger.Info($"Discovered Region: {_discoveryResponse.region.Name} for address: {username}");
|
||||
|
||||
return discoveryResponse;
|
||||
}
|
||||
@@ -84,8 +92,11 @@ public class MimeSharp
|
||||
ArgumentNullException.ThrowIfNull(uri);
|
||||
|
||||
var headers = SetupHeadersWithAuth(customHeaders, uri, uuid, time);
|
||||
_logger.Debug($"Post call headers: {headers.ToJson()}");
|
||||
var bodyJson = body == null ? null : JsonSerializer.Serialize(body);
|
||||
_logger.Debug($"Making POST call to {uri}: {bodyJson}");
|
||||
var response = _webHelper.Post(_region.GetUrl(uri), headers, bodyJson);
|
||||
_logger.Debug($"Post call to {uri}: {response.Result}");
|
||||
return JsonSerializer.Deserialize<DataWrapper<TR>>(response.Result);
|
||||
}
|
||||
|
||||
@@ -95,7 +106,9 @@ public class MimeSharp
|
||||
ArgumentNullException.ThrowIfNull(uri);
|
||||
|
||||
var headers = SetupHeadersWithAuth(customHeaders, uri, uuid, time);
|
||||
_logger.Debug($"Post call headers: {headers.ToJson()}");
|
||||
var response = _webHelper.Get(_region.GetUrl(uri), headers);
|
||||
_logger.Debug($"Post call to {uri}: {response.Result}");
|
||||
return JsonSerializer.Deserialize<DataWrapper<TR>>(response.Result);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="log4net" Version="2.0.17" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -5,5 +5,5 @@ public class DiscoveryResponseWTO
|
||||
public string EmailAddress { get; set; } = string.Empty;
|
||||
public string EmailToken { get; set; } = string.Empty;
|
||||
public string lastAuthType { get; set; } = string.Empty;
|
||||
private RegionDetailsWTO region { get; set; }
|
||||
public RegionDetailsWTO region { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<log4net>
|
||||
<root>
|
||||
<level value="ALL" />
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="file" />
|
||||
</root>
|
||||
<appender name="console" type="log4net.Appender.ConsoleAppender">
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %level %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="file" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="myapp.log" />
|
||||
<appendToFile value="true" />
|
||||
<rollingStyle value="Size" />
|
||||
<maxSizeRollBackups value="5" />
|
||||
<maximumFileSize value="10MB" />
|
||||
<staticLogFileName value="true" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
</log4net>
|
||||
Reference in New Issue
Block a user