|
1 | 1 | Usage |
2 | 2 | ===== |
3 | 3 | Instantiate the client with your DSN: |
| 4 | + |
4 | 5 | ```csharp |
5 | 6 | var ravenClient = new RavenClient("http://public:secret@example.com/project-id"); |
6 | 7 | ``` |
@@ -31,24 +32,128 @@ ravenClient.CaptureMessage("Hello World!"); |
31 | 32 |
|
32 | 33 | Additional Data |
33 | 34 | --------------- |
34 | | -The capture methods allow you to provide additional data to be sent with your request. CaptureException supports both the |
35 | | -`tags` and `extra` properties, and CaptureMessage additionally supports the `level` property. |
| 35 | +You can add additional data to the [`Exception.Data`](https://msdn.microsoft.com/en-us/library/system.exception.data.aspx) |
| 36 | +property on exceptions thrown about in your solution: |
| 37 | + |
| 38 | +```csharp |
| 39 | +try |
| 40 | +{ |
| 41 | + // ... |
| 42 | +} |
| 43 | +catch (Exception exception) |
| 44 | +{ |
| 45 | + exception.Data.Add("SomeKey", "SomeValue"); |
| 46 | + throw; |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +The data `SomeKey` and `SomeValue` will be captured and presented in the `extra` property on Sentry. |
| 51 | + |
| 52 | +Additionally, the capture methods allow you to provide additional data to be sent with your request. |
| 53 | +`CaptureException` supports both the `tags` and `extra` properties, and `CaptureMessage` additionally |
| 54 | +supports the `level` property. |
36 | 55 |
|
37 | 56 | The full argument specs are: |
38 | 57 |
|
39 | 58 | ```csharp |
40 | | -CaptureException(Exception e, IDictionary<string, string> tags = null, object extra = null) |
41 | | -CaptureMessage(string message, ErrorLevel level = ErrorLevel.info, Dictionary<string, string> tags = null, object extra = null) |
| 59 | +string CaptureException(Exception exception, |
| 60 | + SentryMessage message = null, |
| 61 | + ErrorLevel level = ErrorLevel.Error, |
| 62 | + IDictionary<string, string> tags = null, |
| 63 | + string[] fingerprint = null, |
| 64 | + object extra = null) |
| 65 | + |
| 66 | +string CaptureMessage(SentryMessage message, |
| 67 | + ErrorLevel level = ErrorLevel.Info, |
| 68 | + IDictionary<string, string> tags = null, |
| 69 | + string[] fingerprint = null, |
| 70 | + object extra = null) |
| 71 | + |
| 72 | +``` |
| 73 | + |
| 74 | +Async Support |
| 75 | +------------- |
| 76 | +In the .NET 4.5 build of SharpRaven, there are `async` versions of the above methods as well: |
| 77 | + |
| 78 | +```csharp |
| 79 | +Task<string> CaptureExceptionAsync(Exception exception, |
| 80 | + SentryMessage message = null, |
| 81 | + ErrorLevel level = ErrorLevel.Error, |
| 82 | + IDictionary<string, string> tags = null, |
| 83 | + string[] fingerprint = null, |
| 84 | + object extra = null); |
| 85 | + |
| 86 | +Task<string> CaptureMessageAsync(SentryMessage message, |
| 87 | + ErrorLevel level = ErrorLevel.Info, |
| 88 | + IDictionary<string, string> tags = null, |
| 89 | + string[] fingerprint = null, |
| 90 | + object extra = null); |
| 91 | +``` |
| 92 | + |
| 93 | +Nancy Support |
| 94 | +------------- |
| 95 | +You can install the [SharpRaven.Nancy](https://www.nuget.org/packages/SharpRaven.Nancy) package to capture the HTTP context |
| 96 | +in [Nancy](http://nancyfx.org/) applications. It will auto-register on the `IPipelines.OnError` event, so all unhandled |
| 97 | +exceptions will be sent to Sentry. |
| 98 | + |
| 99 | +The only thing you have to do is provide a DSN, either by registering an instance of the `Dsn` class in your container: |
| 100 | + |
| 101 | +```csharp |
| 102 | +protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) |
| 103 | +{ |
| 104 | + container.Register(new Dsn("http://public:secret@example.com/project-id")); |
| 105 | +} |
42 | 106 | ``` |
43 | 107 |
|
| 108 | +or through configuration: |
| 109 | + |
| 110 | +```xml |
| 111 | +<configuration> |
| 112 | + <configSections> |
| 113 | + <section name="sharpRaven" type="SharpRaven.Nancy.NancyConfiguration, SharpRaven.Nancy" /> |
| 114 | + </configSections> |
| 115 | + <sharpRaven> |
| 116 | + <dsn value="http://public:secret@example.com/project-id" /> |
| 117 | + </sharpRaven> |
| 118 | +</configuration> |
| 119 | +``` |
| 120 | + |
| 121 | +The DSN will be picked up by the auto-registered `IRavenClient` instance, so if you want to send events to |
| 122 | +Sentry, all you have to do is add a requirement on `IRavenClient` in your classes: |
| 123 | + |
| 124 | +```csharp |
| 125 | +public class LoggingModule : NancyModule |
| 126 | +{ |
| 127 | + private readonly IRavenClient ravenClient; |
| 128 | + |
| 129 | + public LoggingModule(IRavenClient ravenClient) |
| 130 | + { |
| 131 | + this.ravenClient = ravenClient; |
| 132 | + } |
| 133 | +} |
| 134 | +```` |
| 135 | + |
| 136 | +Debugging SharpRaven |
| 137 | +-------------------- |
| 138 | + |
| 139 | +If an exception is raised internally to `RavenClient` it is logged to the Console. To extend this behaviour use |
| 140 | +the property `ErrorOnCapture`: |
| 141 | + |
| 142 | +```csharp |
| 143 | +ravenClient.ErrorOnCapture = exception => { |
| 144 | + // custom code here |
| 145 | +}; |
| 146 | +```` |
| 147 | + |
| 148 | + |
44 | 149 | Get it! |
45 | 150 | ------- |
46 | 151 | You can clone and build SharpRaven yourself, but for those of us who are happy with prebuilt binaries, there's [a NuGet package](https://www.nuget.org/packages/SharpRaven). |
47 | 152 |
|
48 | 153 | Resources |
49 | 154 | --------- |
50 | | -* [Build Status](http://teamcity.codebetter.com/project.html?projectId=project344&tab=projectOverview) (requires registration) |
| 155 | +* [/statusIcon)](http://teamcity.codebetter.com/viewType.html?buildTypeId=bt1000&guest=1) |
| 156 | +* [](https://gitter.im/getsentry/raven-csharp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
51 | 157 | * [Code](http://github.com/getsentry/raven-csharp) |
52 | 158 | * [Mailing List](https://groups.google.com/group/getsentry) |
53 | | -* [IRC](irc://irc.freenode.net/sentry) (irc.freenode.net, #sentry) |
54 | | -* [](https://gitter.im/getsentry/raven-csharp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
| 159 | +* [IRC](irc://irc.freenode.net/sentry) (irc.freenode.net, #sentry) |
0 commit comments