-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainPage.xaml.cs
90 lines (76 loc) · 2.21 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using Microsoft.Extensions.Logging;
namespace DotNetMaui;
public partial class MainPage
{
private readonly ILogger<MainPage> _logger;
private int _count = 0;
// NOTE: You can only inject an ILogger<T>, not a plain ILogger
public MainPage(ILogger<MainPage> logger)
{
_logger = logger;
InitializeComponent();
}
protected override void OnAppearing()
{
#if !ANDROID
JavaCrashBtn.IsVisible = false;
#endif
#if !__MOBILE__
NativeCrashBtn.IsVisible = false;
#endif
base.OnAppearing();
}
private void OnCounterClicked(object sender, EventArgs e)
{
_count++;
if (_count == 1)
{
CounterBtn.Text = $"Clicked {_count} time";
}
else
{
CounterBtn.Text = $"Clicked {_count} times";
}
SemanticScreenReader.Announce(CounterBtn.Text);
_logger.LogInformation("The button has been clicked {ClickCount} times", _count);
}
private void OnUnhandledExceptionClicked(object sender, EventArgs e)
{
#pragma warning disable CS0618
SentrySdk.CauseCrash(CrashType.Managed);
#pragma warning restore CS0618
}
private void OnBackgroundThreadUnhandledExceptionClicked(object sender, EventArgs e)
{
#pragma warning disable CS0618
SentrySdk.CauseCrash(CrashType.ManagedBackgroundThread);
#pragma warning restore CS0618
}
private void OnCapturedExceptionClicked(object sender, EventArgs e)
{
try
{
throw new ApplicationException("This exception was thrown and captured manually, without crashing the app.");
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
}
private void OnJavaCrashClicked(object sender, EventArgs e)
{
#if ANDROID
#pragma warning disable CS0618
SentrySdk.CauseCrash(CrashType.Java);
#pragma warning restore CS0618
#endif
}
private void OnNativeCrashClicked(object sender, EventArgs e)
{
#if __MOBILE__
#pragma warning disable CS0618
SentrySdk.CauseCrash(CrashType.Native);
#pragma warning restore CS0618
#endif
}
}