How to exclude unwanted items from Azure Diagnostics Trace - azure

I have setup Azure Diagnostics and using Trace to log any messages.
The problem is that when I go to the Azure WADLogsTable, I see that in addition to my messages there is a lot of crap that I want to eliminate.
How do I remove mesages like these?
IDependencyResolver.GetService<ASP._Page_Views_Account_Login_cshtml>() = ASP._Page_Views_Account_Login_cshtml
IDependencyResolver.GetService<System.Web.Mvc.ModelMetadataProvider>() = null
The only thing that I want to show are the things that I put there like this:
Trace.WriteLine("This is not good", "Information");

Make sure that your web.config does not contain any Trace config statements that send system messages to trace.

Related

Why is App Insights only showing Warning and Error tracing levels? What about lower levels?

I have a .Net Framework 4.5.1 app service that has the following code:
Console.WriteLine("πŸ”₯ Console.WriteLine");
Trace.WriteLine("πŸ”₯ Trace.WriteLine");
Trace.TraceInformation("πŸ”₯ Trace.TraceInformation");
Trace.TraceWarning("πŸ”₯ Trace.TraceWarning");
Trace.TraceError("πŸ”₯ Trace.TraceError");
I would like to be able to see logs that we log into Azure when the app is in production. So I enabled Application Service Logging for my web app:
As you can see, I have the logging level set to verbose because we want to see everything. I also have Application Insights turned on for my app. But when I check the logs, all I see are the logs at the warning level and higher.
I checked in the "logs" tab:
I also checked in my blob storage. I see logs, but they're all on a warning level or higher.
There was one way I got this to work, and that's using the feature that saves logs to a file system. But that feature turns itself off after 12 hours, and the file might get too big anyways, and I'd like to use Azure Insights since it has a nicer interface.
How can I view all my logs my application outputs over a long period of time?
I usually just remove all logging configuration from config files like appsettings.json and use the ApplicationInsightsLoggerProvider type specifier in Startup.cs, like so:
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(conf =>
{
conf.AddApplicationInsights();
conf.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.Information);
conf.AddFilter<ApplicationInsightsLoggerProvider>("Microsoft", LogLevel.Warning);
conf.AddFilter<ApplicationInsightsLoggerProvider>("System", LogLevel.Warning);
});
...
}
It's documented here.
If you have various trace levels in your web app but are only interested in having certain levels of logs sent to the logging endpoint, you can set a filter for the minimum level in your application settings under Configuration. By default, even without the app setting, the minimum trace level is set to Warning.
How to set App setting for AppServiceAppLogs level
The application setting name will be APPSERVICEAPPLOGS_TRACE_LEVEL and the value will be the minimum level (ie. Error, Warning, Verbose, etc.). Refer to TraceLevel for more info.
Links
https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs
https://azure.github.io/AppService/2020/08/31/AzMon-AppServiceAppLogs.html (Image Source)

Azure Function is not logging LogMetric telemetry to Application Insights

I have a 3-week-old Function on the v2 SDK and uses the out-box App Insights support, i.e. just set the environment variable and ...magic.
I did read that by default it doesn't send Information level logs to AppInsights and this looks correct because I can't see any of my information tracing but I do see occasional errors I've logged out with my custom message.
But for metrics, its broken. I can see some semblance of my telemetry in the logs, sort of. It's strange.
Look.
Now look at these curious logs.
...see those n/a that match the LogMetric lines in my code?
And when I search explicitly for one of them, nothing is found.
And if I drill down on those n/a logs.
...they're pretty empty.
Is it me or is this all rather fishy?
How do I log metrics from a Function in a way that works?
First, for the metric, do you mean custom metrics? If yes, then you should find it in the customMetrics table in your app insights.
Second, what's the method are you using to send metrics? From your code, what's the implementation of this.Logger?.LogMetric method?
For sending metrics, you can use TrackMetric(just tested with this method, and works) or GetMetric method.
A sample code use TrackMetric(deprecated, but still can use) / GetMetric(recommended) method:
TelemetryConfiguration.Active.InstrumentationKey = "your key";
TelemetryClient client = new TelemetryClient();
client.TrackMetric("my metric", 60);
client.GetMetric("my metric").TrackValue(89);
client.Flush();
In my case, the settings in the host.json file were excluding the metrics from getting to Application Insights. The metrics are being logged at the Information level and I originally had mine configured for the Warning level.
"logging": {
"logLevel": {
"Function.<function name>": "Information", //<--won't see metrics if set to Warning
...
See here for more information on configuring the logging levels.

Pre azure start up

We are sending all trace logs to our NLog logger. (with a trace listener)
Nlog is configured to work with DryIoC.
Locally this works perfect, however, in Azure (web app), the first trace message is logged, before we could create our DryIoc container. Even a PreAppStartMethodAttribute does not help, as the trace log has occurred even before the PreAppStartMethodAttribute.
Is there a way to do some initialization tasks before azure logs it's first trace message?
I found a work-around by using an async wrapper that prevents NLog from flushing the data until the container/configuration has been initiliazed.

How to trace log level changes caused by .ConfigureAndWatch

Using .ConfigureAndWatch we have configured log4net to reconfigure its logging level without restarting application processes.
A process start we trace the currently configured log level to our trace file.
How can we detect and trace to our trace files the log level changes happening through .ConfigureAndWatch?
I just (re)discovered that ILoggerRepository has a ConfigurationChanged event.
Tracing log level changes from there works fine.
private static void repository_ConfigurationChanged(object sender, System.EventArgs e)
{
var currentTracelLevel = ((log4net.Repository.Hierarchy.Logger)_trace.Logger).EffectiveLevel;
_trace.InfoFormat("----------------------------- log4net level={0}", currentTracelLevel);
}
You can activate the log4net internal debugging, then you will receive messages from the ConfigureAndWatchHandler class when a change occurs, either on the console or in the trace output (see link for more information)
re your comment: In order to pull back the event into your own code and not rely on the console or trace output I'd recommend creating a custom trace appender that loops back into log4net. This way you can filter out messages you want to bring back into your own logs.

Getting Azure Logs from role process

I've configured the Azure Diagnostics so that the logs get uploaded to a storage table. I'm using Trace.TraceXxx from my code and all works well.
Now I'm trying to add tracing from the Role OnStart() and OnStop() methods. I know that the tracing works as I see the lines in the Debug window when running in the emulator. But from the cloud deployment, it seems that these trace lines never get uploaded to the table. My guess is that it is somewhat related to TraceSources, as the only trace lines I've in the table come from the w3wp.exe source... Any hint ?
Thanks
Like you said you can add the trace listener using the WaIISHost.exe.config, but besides that you can also add the trace listener in code (you'll need a reference to Microsoft.WindowsAzure.Diagnostics.dll):
public class WebRole : RoleEntryPoint
{
public override void Run()
{
var listener = new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener();
Trace.Listeners.Add(listener);
...
}
}
Another way of setting up diagnostics is through the configuration file. If you created a VS solution recently, it will automatically create the diagnostics plug-in and configuration for the trace listener. With the config file (diagnostics.wadcfg) there is no code that needs to be written for the different data sources. Here is a link where you can get started and a sample file:
http://msdn.microsoft.com/en-us/library/gg604918.aspx
You cannot include custom performance counters right now and you need to make sure that you don’t try to allocate more than 4GB of buffer to anything (you can leave at 0), or it tends to fail.
Note, the time interval format (e.g PT1M). That is a serialization format, so PTXM is X minutes, while PTXS is X in seconds. You need to mark this as content and copy always in Visual Studio (place at root of project) so it gets packaged.
And here is a link to the three ways to setup diagnostics
http://msdn.microsoft.com/en-us/library/windowsazure/hh411541.aspx
Ranjith
http://www.opstera.com

Resources