I have app insights set up in my .net core app and in the logs I see these request traces:
Request starting HTTP/1.1 GET
Request finished in 1.0838ms 404
These are being logged quite a bit and are pushing up the billing. How can I switch these off?
If you want to disable telemetry conditionally and dynamically, you can resolve the TelemetryConfiguration instance with an ASP.NET Core dependency injection container anywhere in your code and set the DisableTelemetry flag on it.
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, TelemetryConfiguration configuration)
{
configuration.DisableTelemetry = true;
...
}
Result:
The preceding code sample prevents the sending of telemetry to Application Insights. It doesn't prevent any automatic collection modules from collecting telemetry. If you want to remove a particular auto collection module, see remove the telemetry module.
Quite likely these are coming from ILogger logs. You can use a filter to not collect ILogger logs based on category. You'll need to find the category and apply a filter, so that these logs don't get sent to ApplicationInsights.
The following completely disables ILogger logs from all category. You'd want something more custom, and you can adjust the filter accordingly.
builder.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.None);
https://learn.microsoft.com/azure/azure-monitor/app/ilogger#create-filter-rules-in-configuration-with-appsettingsjson
I fixed this issue by applying the filter for ApplicationInsights in appsettings.json. This will log categories that start with "Microsoft.AspNetCore" at level "LogLevel.Warning" and higher only.
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Information",`
"Microsoft.AspNetCore": "Warning"
}
}
},
See: https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger#create-filter-rules-in-configuration-with-appsettingsjson
Related
In some request, I need to change this alert to be somewhere on the screen, so how I can disable the default behavior when failing the request the alert show up by abp.message.error and I need to disable it and use another way.
You can send all exception details to the client easily. There's a setting for this purpose.
...
using Abp.Web.Configuration;
...
public override void PreInitialize()
{
Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = true;
}
...
References:
Related Aspnet Boilerplate document
Throwing user friendly exception forum post
Related GitHub commit
Yet another related GitHub issue
Besides, you can disable exception handling for an application service or for an application service method. Just use [DontWrapResult] attribute for that.
public interface ITestAppService : IApplicationService
{
[DontWrapResult]
DoItOutput DoIt(DoItInput input);
}
See the related Aspnet Boilerplate docs
I am trying to set up streaming from an Azure VM scale set to an event hub via Diagnostics configuration.
I have my public config which includes the SinksConfig as follows (I have omitted the rest of the config for the sake of brevity):
{
"WadCfg": {
"DiagnosticMonitorConfiguration": {
*** config for performance counters and ETW ***
"SinksConfig": {
"Sink": [
{
"name": "eventhub",
"EventHub": {
"Url": "sb://myhub.servicebus.windows.net/mycompanyapplication",
"SharedAccessKeyName": "RootManageSharedAccessKey"
}
}
]
}
},
"StorageAccount": "<storageaccount>"
}
and the private config:
{
"storageAccountName": "<storageaccountname>",
"storageAccountKey": "<storageaccountkey>",
"storageAccountEndPoint": "https://core.windows.net",
"EventHub": {
"Url": "sb://myhub.servicebus.windows.net/mycompanyapplication",
"SharedAccessKeyName": "RootManageSharedAccessKey",
"SharedAccessKey": "<sharedaccesskey>"
}
}
However, nothing is being received by the event hub. I can see in the storage account logs that the Diagnostics extension is running:
but in the substatus there are many errors around the SAS key and the event hub:
When I check back in the Visual Studio Diagnostics configuration on the Scale set I see this error:
I have checked the naming convention on the SharedAccessKeyName (which is the default provided when the event hub was set up) know that the SAS key works as I wrote a console app to send messages to the same event hub with the same credentials and it worked fine.
So there is obviously a problem with the authentication to the event hub as it can't read the access key from the config file. However, I can't see any other way of providing it.
Am I missing something obvious here in my config?
Turns out the problem was quite simple, I had grabbed the URL from the connection string in the portal which was
sb://myhub.servicebus.windows.net/mycompanyapplication
when it should have been
https://myhub.servicebus.windows.net/mycompanyapplication
Now the data is flowing freely into the event hub.
However, the diagnostics config in VS still shows the warning about not being able to read the SAS key, which now looks like a "red herring" that ended up costing me a lot of time :(
In my ASP.NET MVC 3 app, I've configured Elmah, and then Elmah.MVC for error logging. Both of which log just fine when running on localhost (Windows 7, IIS 6.1). On a production server (2008 R2, IIS 6.1), no errors are logged. I can browse to the /elmah directory in the site without problem (I've allowed remote access for now.) I've set the proper permissions to a folder for XML logging but nothing logged. I back-tracked to use the "in memory" logger, still no log. I've made sure modules and handlers were referenced correctly in both system.web and system.webserver.
I've browsed a lot of posts related to Elmah config issues, permissions, etc., but have not yet found the cause of this.
Are there other security/permissions issues that I'm missing on the production server related to Elmah? What else could be causing this?
Make sure you do NOT have "Read Only" checked on the folder. thanks
Not sure if this is still current but I was having a similar issue: it all worked perfectly on my local computer and on the web server when you had customErrors mode="Off" but if you changed customErrors to RemoteOnly then it would only work if you accessed the website locally.
The solution was to add a new Elmah filter on the FilterConfig section that guarantees elmah will always log the errors regardless of the customErrors mode. Here is the post with details: http://forums.asp.net/t/1687875.aspx?Elmah+Error+Log+is+not+working+my+production+Server
Here is the code snippet (credit to the person on the post):
public class FilterConfig {
public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
filters.Add(new ElmahHandledErrorLoggerFilter());
filters.Add(new HandleErrorAttribute());
}
}
public class ElmahHandledErrorLoggerFilter : IExceptionFilter {
public void OnException(ExceptionContext context) {
//if (context.ExceptionHandled) // Log only handled exceptions, because all other will be caught by ELMAH anyway.
//We want elmah to log ALL exceptions
ErrorSignal.FromCurrentContext().Raise(context.Exception);
}
}
I can enable tracing by replacing the default No Op trace writer.
GlobalConfiguration.Configuration.Services.Replace(typeof(ITraceWriter), new SimpleTracer());
But how can I disable (and enable it again) while the server is running?
The Enum "TraceLevel" has the option TraceLevel.Off.
Is there a way to set the tracing-framwork form web api to TraceLevel.Off?
Take a look at this article here.
WebApi does not provide any way to configure trace writers regarding their current category or level.
And
Determining which categories and levels are currently enabled is the
responsibility of the ITraceWriter implementation. The Web API
framework has no concept of trace configuration or determining which
categories and levels are enabled.
The intent of this approach is to rely on the ITraceWriter
implementation’s own mechanisms to configure what gets traced and
where.
For example, if you use an NLog-specific ITraceWriter, you should
configure tracing through NLog configuration mechanisms.
In short if you want to enable and disable your tracing or chose not to log a trace for a particular level it is up to you to implement inside your SimpleTracer.
You could create your own threadsafe singleton TraceConfiguration (akin to GlobalConfiguration) implementation to control the trace configuration to allow toggling on or off within the code.
public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
{
if(TraceConfiguration.Configuration.IsEnabled)
{
//trace
}
}
Or you could set and access properties on the request object to determine whether to enable tracing or not. This could be set by ActionFilters on actions and controllers or even set within the controller.
public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
{
if(request.Properties["SupressTracing"] as string != "true")
{
//trace
}
}
Or as the article suggests if you are using NLog or Log4Net etc it is up to you set the levels enabled via config etc.
Can anyone explain why DbgView misses some of my trace writes ?
I'm using the Enterprise Library 5.0 logging block with a trace listener deriving from the EntLib CustomTraceListener, as below ...
[ConfigurationElementType(typeof(CustomTraceListenerData))]
public class DebugTraceListener : CustomTraceListener
{
public override void Write(string message)
{
Debug.Write(message);
}
public override void WriteLine(string message)
{
Debug.WriteLine(message);
}
public override void TraceData(TraceEventCache eventCache, string source,
TraceEventType eventType, int id, object data)
{
if (data is LogEntry && Formatter != null)
{
WriteLine(Formatter.Format(data as LogEntry));
}
else
{
WriteLine(data.ToString());
}
}
}
I can see all the trace in both the Resharper test runner in VS2010, and in the NUnit GUI tester.
I can also send the trace to a flat file listener and this captures all the trace writes,
BUT when I use DbgView (and also TraceSpy) only some of the trace is being shown.
The other wrinkle is I'm using PostSharp to add the logging as an aspect, via attribute, rather than directly in the business code
I've seen this happen when you have another application running that is also capturing some part of the debug traffic. If you're running an application and have VS2010 debugging some component you won't see whatever debug output is being routed to the IDE instead of DebugView. This can be handy if you're testing client-server applications on the same box at the same time but can cause the issue you describe. Short of that I'd just make sure that Capture Global Win32 is checked from the Capture menu as well (I've seen that make a difference even when I wouldn't have expected it to).
Are the missing messages always the same ones?