Skip to content

Commit f17dd05

Browse files
Merge pull request #5 from MindscapeHQ/Remove-attach-method
Remove attach method
2 parents d95103f + 2b739c4 commit f17dd05

File tree

2 files changed

+29
-61
lines changed

2 files changed

+29
-61
lines changed

Mindscape.Raygun4Unity/RaygunClient.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace Mindscape.Raygun4Unity
1010
{
1111
public class RaygunClient
1212
{
13-
private static RaygunClient _current;
14-
1513
private readonly string _apiKey;
1614

1715
/// <summary>
@@ -67,42 +65,6 @@ protected bool OnSendingMessage(RaygunMessage raygunMessage)
6765
/// </summary>
6866
public event EventHandler<RaygunSendingMessageEventArgs> SendingMessage;
6967

70-
/// <summary>
71-
/// Causes Raygun to listen to and send all unhandled exceptions.
72-
/// </summary>
73-
/// <param name="apiKey">Your app api key.</param>
74-
public static void Attach(string apiKey)
75-
{
76-
Detach();
77-
_current = new RaygunClient(apiKey);
78-
Application.RegisterLogCallback(HandleException);
79-
}
80-
81-
/// <summary>
82-
/// Detaches Raygun from listening to unhandled exceptions.
83-
/// </summary>
84-
public static void Detach()
85-
{
86-
Application.RegisterLogCallback(null);
87-
}
88-
89-
private static void HandleException(string message, string stackTrace, LogType type)
90-
{
91-
if (type == LogType.Exception || type == LogType.Error)
92-
{
93-
RaygunMessage raygunMessage = _current.BuildMessage(message, stackTrace, null, null);
94-
_current.Send(raygunMessage);
95-
}
96-
}
97-
98-
/// <summary>
99-
/// Gets the <see cref="RaygunClient"/> created by the Attach method.
100-
/// </summary>
101-
public static RaygunClient Current
102-
{
103-
get { return _current; }
104-
}
105-
10668
/// <summary>
10769
/// Transmits Unity exception information to Raygun.io synchronously.
10870
/// </summary>

README.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,56 @@ The main classes can be found in the Mindscape.Raygun4Unity namespace.
2828
Usage
2929
====================
3030

31-
Raygun4Unity can be used in two main ways: automatically, and manually.
32-
33-
####Automatically
34-
35-
You can setup Raygun4Unity to automatically send all unhandled exceptions with the following single line of code. This code should be placed in a C# script file that will be called in the initialization process of the game.
36-
37-
```
38-
RaygunClient.Attach("YOUR_APP_API_KEY");
39-
```
40-
41-
**WARNING** The RaygunClient uses Application.RegisterLogCallback to listen to exceptions. RegisterLogCallback can only have one handler at a time, so if you already are using RegisterLogCallback,
42-
then you'll want to send the exception information manually within your existing callback.
43-
44-
####Manually
45-
46-
If you already have your own centralized logging system in place, then you many want to send messages to Raygun.io manually within your logging handlers.
47-
This can be done by createing a new instance of RaygunClient and using one of the Send method overloads. There are 3 different types of data that you can use in the Send methods:
31+
To send exception messages to your Raygun.io dashboard, create an instance of the RaygunClient by passing your application API key into the constructor. Then call one of the Send methods.
32+
There are 3 different types of exception data that you can use in the Send methods:
4833

4934
* **Strings** provided by Unity for the error message and stack trace.
5035
* **Exception** .Net objects. Useful if you need to send handled exceptions in try/catch blocks.
5136
* **RaygunMessage** Allowing you to fully specify all the data fields that get sent to Raygun.io
5237

38+
If you already have a central place in your game for catching unhandled exceptions (to write the details to a log for example), then that will be a great place to send the exception information to Raygun.io.
39+
If you aren't currently catching unhandled exceptions in your game, then a good way to do this is by listening to Application.RegisterLogCallback.
40+
In the following example, Application.RegisterLogCallback has been set up in a MonoBehaviour that will be run during the initialization process of the game.
41+
In the handler, you can check to see if the type of the log is an exception or error. Alternatively, you could send all types of log messages.
42+
5343
```
54-
RaygunClient client = new RaygunClient("YOUR_APP_API_KEY");
55-
client.Send(e);
44+
public class Logger : MonoBehaviour
45+
{
46+
void Start ()
47+
{
48+
Application.RegisterLogCallback(HandleException);
49+
}
50+
51+
private void HandleException(string message, string stackTrace, LogType type)
52+
{
53+
if (type == LogType.Exception || type == LogType.Error)
54+
{
55+
RaygunClient client = new RaygunClient("YOUR_APP_API_KEY");
56+
client.Send(message, stackTrace);
57+
}
58+
}
59+
}
5660
```
5761

62+
**WARNING** RegisterLogCallback can only have one handler at a time, so if you already are using RegisterLogCallback,
63+
then you'll want to send the exception information to Raygun.io within your existing callback.
64+
5865
Options
5966
====================
6067

6168
####Application version
6269

6370
The current version of Raygun4Unity does not automatically obtain the application version number. You can however specify this by setting the ApplicationVersion property of the RaygunClient instance.
64-
If you are using the Attach method, you can get the RaygunClient instance from the static RaygunClient.Current property.
6571

6672
####User
6773

68-
To keep track of how many users are affected by each exception, you can set the User property of the RaygunClient instance. This can be any id string of your choosing to identify each user.
74+
To keep track of how many users are affected by each exception, you can set the User or UserInfo property of the RaygunClient instance. The user can be any id string of your choosing to identify each user.
6975
Ideally, try to use an id that you can use to relate back to an actual user such as a database id, or an email address. If you use an email address, the users gravitars (if found) will displayed on the Raygun.io error dashboards.
70-
If you are using the Attach method, you can get the RaygunClient instance from the static RaygunClient.Current property.
76+
The UserInfo property lets you provide additional user information such as their name.
7177

7278
####Tags and custom data
7379

74-
The Send method overloads allow you to send an optional list of tags or a dictionary of object data. You can use these to provide whatever additional information you want to help you debug exceptions.
80+
The Send method overloads allow you to send an optional list of tags or/and a dictionary of object data. You can use these to provide whatever additional information you want to help you debug exceptions.
7581

7682
####Message modifications before sending
7783

0 commit comments

Comments
 (0)