Communicate.Archeo
1.0.12
See the version list below for details.
dotnet add package Communicate.Archeo --version 1.0.12
NuGet\Install-Package Communicate.Archeo -Version 1.0.12
<PackageReference Include="Communicate.Archeo" Version="1.0.12" />
paket add Communicate.Archeo --version 1.0.12
#r "nuget: Communicate.Archeo, 1.0.12"
// Install Communicate.Archeo as a Cake Addin #addin nuget:?package=Communicate.Archeo&version=1.0.12 // Install Communicate.Archeo as a Cake Tool #tool nuget:?package=Communicate.Archeo&version=1.0.12
Usage
This package is used to easily connect your C# application to the Archeo logging application.
To start logging to Archeo you need to specify what happens if you loose your connection to Archeo. We specify this by implementing the IBackupLogger
interface. Logging failures can happen in a multitude of scenarios and you should implement alerting on the backup logger to make your organization aware of potential failures. A simple backup logger implementation could look something like this if you use Application Insights as the backup logger reciever: (Any backup logging solution could be implemented, AI is only used as an example.)
public class BackupLogger : IBackupLogger
{
private string AiKey { get; set; }
private TelemetryClient telemetryClient;
public BackupLogger()
{
AiKey = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process);
telemetryClient = new TelemetryClient() { InstrumentationKey = AiKey };
}
public void LogInformation(string log)
{
var evt = new EventTelemetry(log);
telemetryClient.TrackEvent(evt);
}
public void LogError(string message, List<LogStep> logSteps)
{
telemetryClient.TrackTrace(message, new Dictionary<string, string>() { { "Logstep object", JsonConvert.SerializeObject(logSteps) } });
}
public void LogException(Exception e, List<LogStep> logSteps)
{
telemetryClient.TrackException(e, new Dictionary<string, string>() { { "Logstep object", JsonConvert.SerializeObject(logSteps) } });
}
}
If you use application insights the team has released a NuGet package with a backup logger implementation for convenience: Communicate.Archeo.BackupLogger.ApplicationInsights
Creating the log object
The Archeo SDK log object supports Dependency Injection as a scoped service only. It's important that you ensure that the object lives only once per web request and not as a singleton.
Using HttpClientFactory
In your startup.cs
you need to declare a HttpClient. You can name it whatever you want but a default name is supplied in the ArcheoDefaults
constants class. The Uri for Archeo is also supplied in ArcheoDefaults
as seen below:
services.AddHttpClient(ArcheoDefaults.HttpClientName, client =>
{
client.BaseAddress = new Uri(ArcheoDefaults.ArcheoEndpoint);
client.DefaultRequestHeaders.Add("APIKEY", GetAppSetting("ArcheoApiKey"));
});
You also need to add the IArcheoLogger
itself as a scoped service. You can use dependency injection to insert both the IHttpFactory
and the IBackupLogger
or you can supply them explicitly:
services.AddScoped<IArcheoLogger>(sp => new ArcheoLogger(sp.GetService<IHttpClientFactory>(), new BackupLogger()));
Or
services.AddScoped<IBackupLogger, BackupLogger>();
services.AddScoped<IArcheoLogger, ArcheoLogger>();
Letting the SDK supply the HttpClient
If you don't want to have a relationship with the HttpClient used for the sending of logs you can use the constructor for ArcheoLogger
like this:
IExtendedBackupLogger backupLogger = new AiExtendedBackupLogger(Settings.GetAppSetting("APPINSIGHTS_INSTRUMENTATIONKEY"));
ArcheoLogger logger = new ArcheoLogger(backupLogger, new ArcheoConfiguration() { ApiKey = Settings.GetAppSetting("ArcheoApiKey") });
Here we also use the AiExtended logger which supplies extra methods for contacting the backup logger.
Supplying the HttpClient yourself
If you don't want to have a relationship with the HttpClient used for the sending of logs you can use the constructor for ArcheoLogger
like this:
IExtendedBackupLogger backupLogger = new AiExtendedBackupLogger(Settings.GetAppSetting("APPINSIGHTS_INSTRUMENTATIONKEY"));
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://google.com");
client.DefaultRequestHeaders.Add("APIKEY", "asd");
ArcheoLogger logger = new ArcheoLogger(client, backupLogger);
Setting up the logger
To avoid having to send every parameter every time you use the logger this nuget provides the Arche.LogBase
object. This object is used if parameters supplied on logging are null. The LogBase should be instantiated as early in the pipeline as possible. You simply set the object like this:
logger.LogBase = new ArcheoLogBase()
{
MessageType = messageType,
Reciever = partyConfig.ReceiverId,
Sender = partyConfig.SenderId,
TransactionId = transactionId,
TransactionTag = transactionTag,
TransactionType = partyConfig.DocumentType
};
Logging
If you set up the LogBase
you only need 2-3 parameters when logging. If you need to override any of the LogBase params on only a single log entry just supply the parameter. This nuget provides 4 logging methods as of now. Please see the code comments for details. Here are some simple examples that only work if LogBase is used:
archeo.LogException((Exception)e, $"Exception occured in {nameof(test)}");
archeo.LogHttpFailure((HttpResponseMessage)result, "Sending file to APIM failed");
archeo.Log(encoding.GetBytes(fileContent), "File successfully downloaded", $"file.file");
archeo.Log(fileContent, "Something failed")
Sending logs
After logging you share of logs you need to call await archeo.SendLogs()
. This is usually done in the finally
clause in the catch all, but you are free to do this whenever you want. When logs are sent the list of logged steps is cleared but the LogBase is kept in case you want to log more withing the same scope. If you want to clear both objects you can call IArcheoLogger.Clear()
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
- Microsoft.Extensions.Http (>= 2.1.1)
- Newtonsoft.Json (>= 11.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Communicate.Archeo:
Package | Downloads |
---|---|
Communicate.Archeo.BackupLogger.ApplicationInsights
Backup logger that uses Application insights as the logging provider |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.5 | 7,904 | 4/1/2022 |
1.2.4 | 3,863 | 3/24/2021 |
1.2.3 | 4,475 | 9/8/2020 |
1.2.2 | 706 | 8/14/2020 |
1.2.1 | 680 | 8/5/2020 |
1.2.0 | 861 | 3/26/2020 |
1.1.8 | 1,437 | 1/21/2020 |
1.1.7 | 1,782 | 11/15/2019 |
1.1.6 | 741 | 11/4/2019 |
1.1.5 | 773 | 10/30/2019 |
1.1.4 | 2,560 | 10/30/2019 |
1.1.3 | 560 | 10/29/2019 |
1.1.2 | 629 | 10/29/2019 |
1.1.1 | 548 | 10/23/2019 |
1.1.0 | 564 | 10/18/2019 |
1.0.19 | 1,292 | 7/26/2019 |
1.0.18 | 669 | 6/18/2019 |
1.0.17 | 585 | 6/18/2019 |
1.0.16 | 549 | 6/17/2019 |
1.0.15 | 594 | 6/14/2019 |
1.0.14 | 686 | 6/7/2019 |
1.0.13 | 645 | 5/6/2019 |
1.0.12 | 682 | 4/24/2019 |
1.0.11 | 642 | 4/24/2019 |
1.0.10 | 666 | 4/24/2019 |
1.0.9 | 648 | 3/27/2019 |
1.0.8 | 602 | 3/26/2019 |
1.0.7 | 605 | 3/26/2019 |
1.0.6 | 592 | 3/26/2019 |
1.0.5 | 607 | 3/25/2019 |
1.0.4 | 598 | 3/25/2019 |
1.0.3 | 641 | 3/22/2019 |
1.0.2 | 615 | 3/21/2019 |
1.0.1 | 2,477 | 2/21/2019 |
0.4.1 | 879 | 2/20/2019 |
0.4.0 | 703 | 2/13/2019 |
0.3.7 | 718 | 12/28/2018 |
0.3.6 | 698 | 12/28/2018 |
0.3.5 | 749 | 12/28/2018 |
0.3.4 | 812 | 10/30/2018 |
0.3.3 | 742 | 10/30/2018 |
0.3.2 | 790 | 10/29/2018 |
0.3.1 | 788 | 10/25/2018 |
0.3.0 | 782 | 10/23/2018 |
0.2.5 | 760 | 10/19/2018 |
0.2.4 | 745 | 10/19/2018 |
0.2.3 | 815 | 10/12/2018 |
0.2.2 | 776 | 10/12/2018 |
0.2.1 | 781 | 10/12/2018 |
0.2.0 | 812 | 10/12/2018 |
0.1.7 | 763 | 10/12/2018 |
0.1.6 | 774 | 10/11/2018 |
0.1.5 | 815 | 10/11/2018 |
0.1.4 | 782 | 10/11/2018 |
0.1.3 | 781 | 10/11/2018 |
0.1.2 | 800 | 10/11/2018 |
0.1.1 | 781 | 10/11/2018 |
0.1.0 | 800 | 10/11/2018 |