DOCUMENTATION

Xamarin.Android and Xamarin.iOS Clients

Add the Logify Alert client to your application's code:

Visual Studio

  • 1. Right-click your Xamarin.Android project in the Solution Explorer and select Manage NuGet Packages...

  • 2. Search for Logify.Alert.Xamarin.Android in the nuget.org package source and click Install.

Visual Studio for Mac

  • 1. In your Xamarin.Android project, right-click the Packages folder and select Add Packages...

  • 2. In the invoked Add Packages dialog, search for Logify.Alert.Xamarin.Android in the nuget.org package source and click Add Package.

Visual Studio

  • 1. Right-click your Xamarin.iOS project in the Solution Explorer and select Manage NuGet Packages...

  • 2. Search for Logify.Alert.Xamarin.iOS in the nuget.org package source and click Install.

Visual Studio for Mac

  • 1. In your Xamarin.iOS project, right-click the Packages folder and select Add Packages...

  • 2. In the invoked Add Packages dialog, search for Logify.Alert.Xamarin.iOS in the nuget.org package source and click Add Package.

Access the Logify Alert client instance:

Use the LogifyAlert.Instance property to get a client instance in your Xamarin.Android or Xamarin.iOS project:

LogifyClient client = LogifyClient.Instance;

To configure the Logify Alert client in your Xamarin.Forms application's .Net Standard project containing the shared code, add the Logify.Alert.Core library to this project and access the client instance as follows:

LogifyClientBase client = LogifyClientBase.Instance;

The Logify Alert client provides the following properties, methods, and events.

Properties

ApiKey

Type: String

Specifies an API Key used to register the applications within the Logify Alert service.

client.ApiKey = "SPECIFY_YOUR_API_KEY_HERE";

AllowRemoteConfiguration

Type: Boolean
Default value: false

Specifies whether a Logify Alert client configuration can be specified remotely.

client.AllowRemoteConfiguration = true;

AppName

Type: String
Default value: null

Specifies an application name.

client.AppName = "My Application";

AppVersion

Type: String
Default value: null

Specifies an application version.

client.AppVersion = "1.0.2";

Attachments

Type: AttachmentCollection

Specifies a collection of files attached to a report. The total attachments size must not be more than 3 Mb per one crash report. The attachment name must be unique within one crash report.

using DevExpress.Logify.Core;
using DevExpress.Logify.Xamarin;

LogifyAlert client = LogifyAlert.Instance;
client.ApiKey = "SPECIFY_YOUR_API_KEY_HERE";

Attachment newAt = new Attachment();
newAt.Name = "MyAttachedImage.jpg";
newAt.Content = File.ReadAllBytes(@"My_files/Image_to_attach.jpg");
// We strongly recommend that you specify the attachment type.
newAt.MimeType = "image/jpeg";

client.Attachments.Add(newAt);
client.StartExceptionsHandling();

CustomData

Type: IDictionary<String, String>

Gets the collection of custom data sent with generated reports.

Use the CustomData property to attach additional information to the generated report. For instance, you can use this property to track additional metrics that are important in terms of your application: CPU usage, environment parameters, and so on.

The field name can only consists of a-z, A-Z, 0-9, and _ characters.

client.CustomData["CustomerName"] = "Mary";

Instance

Type: Singleton

Returns the single instance of the LogifyAlert class.

LogifyAlert client = LogifyAlert.Instance;

OfflineReportsCount

Type: Integer
Default value: 0

Specifies the number of last reports to be kept once an Internet connection is lost. Reports are only saved when the OfflineReportsEnabled property is set to true.

client.OfflineReportsEnabled = true; client.OfflineReportsCount = 20; // Keeps the last 20 reports

OfflineReportsDirectory

Type: String
Default value: "offline_reports"

Specifies a directory path that will be used to store reports once an Internet connection is lost. Reports are only saved when the OfflineReportsEnabled property is set to true.

client.OfflineReportsEnabled = true; client.OfflineReportsDirectory = "<directory-for-offline-reports>";

OfflineReportsEnabled

Type: Boolean
Default value: false

Specifies whether or not Logify should store the last OfflineReportsCount reports once an Internet connection is lost. To send the kept reports once an Internet connection is available, call the SendOfflineReports method.

client.OfflineReportsEnabled = true; client.OfflineReportsCount = 20; // Keeps the last 20 reports client.OfflineReportsDirectory = "<directory-for-offline-reports>";

ProxyCredentials

Type: ICredentials
Default value: null

Specifies proxy credentials (a user name and a password) to be used by Logify Alert to authenticate within your system proxy server. The use of this property resolves the "407 Proxy Authentication Required" proxy error.

client.ProxyCredentials = new NetworkCredential("MyProxyUserName", "MyProxyPassword");

RemoteConfigurationFetchInterval

Type: Integer
Default value: 10

Specifies a time interval, in minutes, in which client configuration set remotely should be automatically loaded from the server. The minimum value is 1.

client.RemoteConfigurationFetchInterval = 5;

Tags

Type: IDictionary<String, String>

Gets the collection of tags specifying additional report fields, which will be used in auto ignoring, filtering or detecting duplicates.

A key is a tag name (a string that consists of a-z, A-Z, 0-9, and _ characters), and a value is a tag value that is saved to a report. A new tag is added with Allow search enabled.

client.Tags["tag_name"] = "tag_value";

UserId

Type: String
Default value: null

Specifies a unique user identifier that corresponds to a sent report.

client.UserId = "user@myapp.com";

Methods

LoadRemoteConfiguration

Loads client configuration parameters specified remotely.

TrackArguments

Collects arguments passed to the invoked method. Call this method when handling an exception that occurs during a method execution.

  • TrackArguments(Exception ex, object instance, params object[] args)
  • TrackArguments(Exception ex, int frameCount, MethodCallInfo call)
  • TrackArguments(Exception ex, MethodCallInfo call, int skipFrames)

public void DoWork(string work) {   LogifyAlert.Instance.ResetTrackArguments();   try {     DoInnerWork(work, 5);     LogifyAlert.Instance.ResetTrackArguments();   }   catch (Exception ex) {     LogifyAlert.Instance.TrackArguments(ex, work);     throw;   } } public void DoInnerWork(string innerWork, int times) {   LogifyAlert.Instance.ResetTrackArguments();   try {     object o = null;     o.ToString();     LogifyAlert.Instance.ResetTrackArguments();   }   catch (Exception ex) {     LogifyAlert.Instance.TrackArguments(ex, this, innerWork, times);     throw;   } }

See the Collect Method Arguments document for details.

ResetTrackArguments

Removes method argument values which TrackArguments collected. Call ResetTrackArguments before a method execution and after method execution succeeds.

Send

Generates a crash report based on the caught exception and sends this report to the Logify Alert service.

  • Send(Exception ex)

    Generates a crash report based on the caught exception and sends this report to the Logify Alert service.

    try {   RunCode(); } catch (Exception e) {   client.Send(e); }

  • Send(Exception ex, IDictionary<String, String> additionalCustomData)

    Sends the caught exception with specified custom data to the Logify Alert service.

    try {   RunCode(); } catch (Exception e) {   var data = new Dictionary<String, String>();   data["FailedOperation"] = "RunCode";   client.Send(e, data); }

  • Send(Exception ex, IDictionary<String, String> additionalCustomData, AttachmentCollection additionalAttachments)

    Sends the caught exception with specified custom data and attachments to the Logify Alert service.

    try {   RunCode(); } catch (Exception e) {   var data = new Dictionary<String, String>();   data["FailedOperation"] = "RunCode";   Attachment newAt = new Attachment();   newAt.Name = "MyAttachedImage.jpg";   newAt.Content = File.ReadAllBytes(@"C:\Work\Image_to_attach.jpg");   // We strongly recommend that you specify the attachment type.   newAt.MimeType = "image/jpeg";   AttachmentCollection newCol = new AttachmentCollection();   newCol.Add(newAt);   client.Send(e, data, newCol); }

SendAsync

Generates a crash report based on the caught exception and sends this report to the Logify Alert service asynchronously.

  • SendAsync(Exception ex)

    Generates a crash report based on the caught exception and sends this report to the Logify Alert service asynchronously.

    try {   RunCode(); } catch (Exception e) {   client.SendAsync(e); }

  • SendAsync(Exception ex, IDictionary<String, String> additionalCustomData)

    Sends the caught exception with specified custom data to the Logify Alert service asynchronously.

    try {
      RunCode(); } catch (Exception e) {   var data = new Dictionary<String, String>();   data["FailedOperation"] = "RunCode";   client.SendAsync(e, data); }

  • SendAsync(Exception ex, IDictionary<String, String> additionalCustomData, AttachmentCollection additionalAttachments)

    Sends the caught exception with specified custom data and attachments to the Logify Alert service asynchronously.

    try {   RunCode(); } catch (Exception e) {   var data = new Dictionary<String, String>();   data["FailedOperation"] = "RunCode";   Attachment newAt = new Attachment();   newAt.Name = "MyAttachedImage.jpg";   newAt.Content = File.ReadAllBytes(@"C:\Work\Image_to_attach.jpg");   // We strongly recommend that you specify the attachment type.   newAt.MimeType = "image/jpeg";   AttachmentCollection newCol = new AttachmentCollection();   newCol.Add(newAt);   client.SendAsync(e, data, newCol); }

SendOfflineReports

Sends all reports saved in the OfflineReportsDirectory folder to the Logify Alert service.

StartExceptionsHandling

Commands Logify Alert to start listening to uncaught exceptions and sends reports for all processed exceptions.

client.StartExceptionsHandling();

StopExceptionsHandling

Commands Logify Alert to stop listening to uncaught exceptions.

client.StopExceptionsHandling();

Events

AfterReportException

Occurs after Logify Alert sends a new crash report to the service.

LogifyAlert.Instance.AfterReportException += OnAfterReportException; void OnAfterReportException(object sender, AfterReportExceptionEventArgs e) {   MessageBox.Show("A new crash report has been sent to Logify Alert", "Crash report", MessageBoxButtons.OK, MessageBoxIcon.Information); }

BeforeReportException

Occurs before Logify Alert sends a new crash report to the service.

The BeforeReportException event occurs between the CanReportException event and sending a new report to the Logify Alert service. If the report send is canceled in the CanReportException event's handler, the report is not sent and the BeforeReportException event isn't raised.

Handle the BeforeReportException event to add custom data to the sent report. To do this, assign the required data to the CustomData property.

LogifyAlert.Instance.BeforeReportException += OnBeforeReportException; void OnBeforeReportException(object sender, BeforeReportExceptionEventArgs e) {   LogifyAlert.Instance.CustomData["LoggedInUser"] = "Mary"; }

CanReportException

Occurs between generating a new crash report and raising the BeforeReportException event.

The CanReportException event occurs right after a new report is generated and is prepared to be sent to the Logify Alert service. Handle the CanReportException event to cancel the report send. To do this, assign true to the appropriate CanReportExceptionEventArgs's Cancel property. Thus, the generated report is not posted to the service and the BeforeReportException isn't raised.

LogifyAlert.Instance.CanReportException += OnCanReportException; void OnCanReportException(object sender, CanReportExceptionEventArgs args) {   if (args.Exception is MyCustomException)     args.Cancel = true; }

Terms of use Copyright © 2016-2023 Developer Express Inc.