I'm using Sentry for logging errors etc. It works fine when creating a SentryEvent with a supplied Exception object. I'm trying to create ones that do not come from an exception, just a condition that needs to be flagged up on the system.
To this extent I've set the exception to null and everything works fine, except that the issue has '' as its title. I can't find anywhere in the SentryEvent object that I can set as a title to avoid this.
How do I label an event manually?
The "title" or "label" provided in the web interface is the "message" property of the event.
If you are using the official Sentry client "SharpRaven", then use CaptureMessage method instead of CaptureException.
RavenClient.CaptureMessage("Whoops!")
If you're working on your own client, or simply use HTTP requests, then set the "Message" of the event in the JSON blob:
{
"message": "Whoops!"
}
Related
When using WebView2 it's possible to call C# methods from JavaScript on the web page by exposing a C# class in WebView2 under window.chrome.webview.hostObjects.sync.NameOfMyApiInterface.
Where you can name the NameOfMyApiInterface what ever you like using:
this.MyWebView2Control.CoreWebView2.AddHostObjectToScript("NameOfMyApiInterface", this);
But I've seen those using other 3rd party Chromium browser plugins putting their API directly under window, like window.NameOfMyApiInterface.
Is this possible using WebView2?
Yes. Although calls to CoreWebView2.AddHostObjectToScript will create proxy objects in script on chrome.webview.hostObjects, you can copy those objects wherever you like. You can make a property on window and have it point to the same proxy object.
For example, if you have an object NameOfMyApiInterface that has a property named Property with value "Example":
console.log(chrome.webview.hostObjects.sync.NameOfMyApiInterface.Property); // 'Example'
window.NameOfMyApiInterface = chrome.webview.hostObjects.sync.NameOfMyApiInterface;
console.log(window.NameOfMyApiInterface.Property); // 'Example'
If you call CoreWebView2.AddHostObjectToScript before navigating to the page that will use NameOfMyApiInterface, you can update that page to do the assignment at the top before other script runs. Or if you don't own or can't update the page, you can use CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync to add the line of script that does the assignment to run before any other script in that page.
I'm receiving the following error in browser:
Cannot provide a value for property 'IconService' on type 'Microsoft.Fast.Components.FluentUI.FluentIcon'. There is no registered service of type 'Microsoft.Fast.Components.FluentUI.IconService'.
https://learn.microsoft.com/en-us/fluent-ui/web-components/components/button?pivots=blazor
https://github.com/microsoft/fast-blazor/blob/main/examples/FluentUI.Demo.Shared/Pages/ButtonPage.razor
https://brave-cliff-0c0c93310.azurestaticapps.net/ButtonPage
This is when using example code from Microsoft Blazor:
<h3>With content and icon</h3>
<h4>With start</h4>
<FluentButton>
Button
<FluentIcon Name="#FluentIcons.Globe" Slot="start" Size="#IconSize.Size16" Filled=false />
</FluentButton>
A single button renders fine but when I use FluentIcon I get a runtime error.
I have followed this getting started guide:
https://learn.microsoft.com/en-us/fluent-ui/web-components/integrations/blazor
I have also looked at Icon examples but with no luck:
https://brave-cliff-0c0c93310.azurestaticapps.net/IconPage
You need to add the code below to Program.cs for your Blazor client. For some reason this is only documented on Github but not https://learn.microsoft.com.
builder.Services.AddFluentUIComponents();
https://github.com/microsoft/fast-blazor
I can do this in .net core
_logger.LogInformation("Token validated {clientId}", "MyId");
And then logging libraries like NLog will know that there is a property called clientId with the value MyId in the message and can render it in a special way.
I am trying to do the same without including the property in the message itself, but cannot manage to nail it. This is what I have done so far and it does not result in a property in NLog:
LogEventInfo info = new LogEventInfo
{
Properties = {{"clientId", "MyId"}},
};
_logger.Log(Microsoft.Extensions.Logging.LogLevel.Information, "Token validated", info, null, info.MessageFormatter);
This results in a message without property. Is there a better way to do this or have I done something wrong?
The whole idea with Microsoft-Extension-Logging (MEL) ILogger-interface is not being dependent on a specific Logging-Framework.
If you start creating NLog LogEventInfo-objects, then you might as well call NLog.LogManager.GetCurrentClassLogger() and use that as Logger.
But maybe this wiki-page can give you some ideas:
https://github.com/NLog/NLog.Extensions.Logging/wiki/NLog-properties-with-Microsoft-Extension-Logging
I have created a custom object that i use to generate a json error response for all error. The issue i am having is there are some errors that i cant catch. For example, if i try to call an action that does not support GET the default response is
{"Message":"The requested resource does not support http method
'GET'."}
This is fine, but i want to control the format. I want to control every single automated error like this so i can make sure that nothing gets output that i dont want to be output. I need to be able to gracefully let the client know if a code exception occurs.
I found this and this seems to be what i am looking for, but it doesnt seem to be catching the errors as there are no matching actions for these . How to override all standard error pages in WebAPI
I tried to implement this, but i still get the same error message from above even when i have this in the main controller.
[AllowAnonymous]
[ActionName("405")]
[HttpGet]
public string Status405()
{
return "error";
}
I was hoping there would be an onerror event or something that would act as a catch all so i could override everything. I tried to work based off the HttpResponseEx
public class ErrorFilter : System.Web.Http.HttpResponseException
{
public override string Message
{
get
{
return "My custom response based on whatever params are in this error";
}
}
}
This doesnt work either and i can see why as it doesnt tap into any events that get triggered.
Surely there is a way to do this. How is it normally done?
In the web.config, you need to turn on custom errors. By default it's set to remote, which allows the developer to see the stack trace and the end user to see a nice error page. You want to set this to on. See here for more details https://msdn.microsoft.com/en-us/library/h0hfz6fc(v=vs.85).aspx
I am writing a mobile service scheduler in my mobile service .net backend source .
When I debug my app, when program calls Controller's getAll() method, get an exception. The message is
"Object reference not set to an instance of an object."
I have a Model named Source, and also have a Controller name SourceController.
SourceController sourceController = new SourceController();
List<Source> sources = new List<Source>();
sources = sourceController.GetAllSource().ToList();
At the line 3, I get this Error :
"Object reference not set to an instance of an object."
I ain't did any changes in Sources controller class. This means in Visual Studio I clicked and add Controller to Source. Also ain't did any changes in DataContext.
Can anybody help?
Unless you are doing unit testing you won't instantiate the controller directly -- it is initialized when a request comes in for an action within the controller.
If you are writing a test then note that your "sources" list isn't assigned to anything so it looks like SourceController.GetAllSource() gets a null source and hence ToList() will fail with the null exception that you see.
Hope this helps,
Henrik