.NET MAUI
A Sample .NET MAUI app using Bugfender is available at Github Bugfender .NET MAUI
We would like to express our gratitude to @AlonRom for his contributions to this project (conversion from Xamarin to .NET MAUI).
Bugfender is a game-changing platform that logs every detail your users experience and feeds the data directly to an easy-to-use web console. Bugfender SDK is multi-platform and available for mobile and web apps, so you can use the same tool for all your apps.
Specifically for .NET MAUI developers, Bugfender offers powerful capabilities to remotely monitor and debug any log or error. You can easily reproduce and fix issues using our detailed log viewer and the stack trace of exceptions.
If you don't have a Bugfender account yet, go to Bugfender Signup and come back here.
Install
Add the NuGet Bugfender.Sdk to your .NET MAUI project.
dotnet add package Bugfender.Sdk --version 3.0.0
Configure
Adding Bugfender to your iOS project
- Edit your project > Properties > Build > iOS > Build and set the Linker behavior to Link Frameworks SDKs Only.
- Edit
AppDelegate.cs
and initialize Bugfender in theFinishedLaunching
method, like this:
using Bugfender.Sdk;
// ...
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
BugfenderBinding bugfender = BugfenderBinding.Instance;
bugfender.Init(new BugfenderOptions
{
appKey = "YOUR_APP_KEY_HERE",
// apiUri = new Uri("https://api.bugfender.com"),
// baseUri = new Uri("https://dashboard.bugfender.com"),
printToConsole = true,
nativeCrashReporting = true,
mauiCrashReporting = true,
logUIEvents = true,
// maximumLocalStorageSize = 5*1024*1024,
});
// some examples on how to use Bugfender
bugfender.WriteLine("Logs for this device are here: {0}", bugfender.DeviceUri.ToString());
bugfender.Warning("TAG", "This is a warning");
bugfender.Error("TAG", "This is an error!");
bugfender.SetDeviceString("user", "[email protected]");
return base.FinishedLaunching(application, launchOptions);
}
Remember to change YOUR_APP_KEY_HERE with the app key of your app. You can get an app key by signing up to Bugfender. For all the available options see our reference.
Adding Bugfender to your Android project
Look for your application object (usually in Platforms/Android/MainApplication.cs
). If you don't have it, create a new application class by right-clicking on Your Project > New File... > General > Empty Class.
Then add the following code:
using Android.App;
using Android.Runtime;
using Bugfender.Sdk;
[Application]
public class MainApplication : Application
{
public MainApplication(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip)
{
}
public override void OnCreate()
{
base.OnCreate();
BugfenderBinding bugfender = BugfenderBinding.Instance;
bugfender.Init(this, new BugfenderOptions
{
appKey = "YOUR_APP_KEY_HERE",
// apiUri = new Uri("https://api.bugfender.com"),
// baseUri = new Uri("https://dashboard.bugfender.com"),
printToConsole = true,
nativeCrashReporting = true,
mauiCrashReporting = true,
logUIEvents = true,
// maximumLocalStorageSize = 5*1024*1024,
});
// some examples on how to use Bugfender
bugfender.WriteLine("Logs for this device are here: {0}", bugfender.DeviceUri.ToString());
bugfender.Warning("TAG", "This is a warning");
bugfender.Error("TAG", "This is an error!");
}
}
Remember to change YOUR_APP_KEY_HERE with the app key of your app. You can get an app key by signing up to Bugfender. For all the available options see our reference.
Other configuration options
apiUri
andbaseUri
: are used to point to a specific Bugfender instance, like a specific region or on-prem instance.nativeCrashReporting
andmauiCrashReporting
: enable crash reports on the native (iOS/Android) and .NET MAUI stacks.maximumLocalStorageSize
: changes the amount of storage the log cache can take on disk. The size is in bytes and can be up to 50 megabytes.
Usage
Send Logs
Use WriteLine("hello world")
as you would use the system-provided Console
, Trace
or Debug
objects.
Tip: If your project is currently using Console
/Trace
/Debug
to write logs, you can search & replace them to Bugfender
to get started quickly.
You may also want to specify a logging level by using the following functions:
Fatal()
Error()
Warning()
Info()
Debug()
Trace()
Bugfender.WriteLine("Logs for this device are here: {0}", bugfender.DeviceUri.ToString());
Bugfender.Warning("TAG", "This is a warning");
Bugfender.Error("TAG", "This is an error!");
Set Device Data
Once your application is running on several devices, it will be useful to know which device belongs to whom. You can associate information to a device as if it were a dictionary using the following functions:
void SetDeviceString(string key, string value)
: associates data to this device so you can search for this device. You can set details like the user ID, so later on you can find the device corresponding to a user easily.void SetDeviceInteger(string key, int value)
: same for integers.void SetDeviceFloat(string key, float value)
: same for floats.void RemoveDeviceKey(string key)
: removes data associated from a device.
Bugfender.SetDeviceString("user.email", "[email protected]");
Bugfender.SetDeviceInteger("user.id", 32);
Bugfender.SetDeviceFloat("user.pi", 3.14);
Send Issues
Bugfender allows you to send issues to the server. An issue is similar to an exception but they are showed in the issues section and you can send issues any time from the app, even if the device is not enabled in the system. Issues are useful to keep track of important errors that you can detect in your code.
For sending an issue you can use the following function:
Uri SendIssue(string title, string content)
: send information about an exceptional situation you need to look into. This will force all logs in the current session to be sent, even if log sending is disabled.
Bugfender.sendIssue("Test Issue", "Issue value goes here!");
Send User Feedback
Getting feedback from the final users is one of the most important things for an app developer. Good user feedback allows you to detect errors in your app and helps you to understand better your product.
Sending User Feedback automatically sends all cached logs for the current session, even if the device is not enabled for sending logs.
Uri SendUserFeedback(string subject, string message)
: send user feedback that will appear in the dashboard. This will force all logs in the current session to be sent, even if log sending is disabled.
Bugfender.SendUserFeedback("Test user feedback", "User feedback details here!");
Advanced Usage
Sending Logs with Tags
You can specify a tag to easily group logs that belong to the same category, for example:
Bugfender.Error("Networking", "Server responded with status 500")
Or you can send a log providing all the information using void Log(int lineNumber, String method, String file, LogLevel logLevel, String tag, String message)
.
Bugfender.log(
42,
"someMethod()",
"someFile",
LogLevel.Info,
"Custom tag",
"This is a custom log"
);
Manually sending crashes
If you have your own crash reporting system and need to send crashes, you can do so by calling directly:
Uri SendCrash(string title, string text)
: manually send crash information
Usually you do not want to use this, enable automated crash reporting instead. This will force all logs in the current session to be sent, even if log sending is disabled.
Having your app decide when to send logs
In some special circumstances you may want to send logs, regardless of the enabled state of the device in the Bugfender console, for example in a custom exception handler. Use ForceSendOnce
to force sending the logs once, and use ForceEnabled
to force it for some period of time.
void ForceSendOnce()
: forces the SDK to send logs for the current session. Can be useful if you want to inspect the logs only for some sessions.bool ForceEnabled { set; }
: forces the SDK to send logs, even if the device is disabled from the dashboard. Use with caution because there is no way to disable logging from the dashboard if you change your mind, prefer to enable devices from the dashboard instead.
//Force to send the logs once
Bugfender.ForceSendOnce();
//Force to send the logs from now on
Bugfender.ForceEnabled(true);
Get Session Link
Sometimes you want to integrate Bugfender with a third party tool. For this purpose, the SDK provides a method that returns the URL for the session. You can send it to the third party tool to easily go to the logs of the current session from the other tool.
Uri SessionUri { get; }
: similar to DeviceUri
, points to the logs of the current execution of the app.
Bugfender.SessionUri();
Get Device Link
Sometimes you want to integrate Bugfender with a third party tool. For this purpose, the SDK provides a method that returns the URL for the current device. You can send it to the third party tool and easily navigate back to the logs of the device from the other tool.
Uri DeviceUri { get; }
: the device URI can be used to see the logs of this device in the Bugfender Dashboard. Useful if you want to integrate Bugfender deeper in your workflow, such as showing the Bugfender URL of a device in your help desk software.
Bugfender.DeviceUri();
Full reference
This project is wrapping the native iOS and Android SDKs. You have the full reference here:
- For more information, have a look at the iOS SDK.
- For more information, have a look at the Android SDK.