I'm trying to get trace output from a particular trace source onto Azure Portal's Log Stream. However, this does not seem to work
<system.diagnostics>
<sharedListeners>
<add name="txtListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="SchoolsDirectoryLog.log" />
</sharedListeners>
<sources>
<source name="SkyNet" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="txtListener" />
</listeners>
</source>
</sources>
<switches>
<add name="sourceSwitch" value="Error, Information, Warning, Verbose" />
</switches>
</system.diagnostics>
Related
I have deployed a Asp.Net Core 2 app to IIS. The app is running fine but it keeps creating the following directory structure in the disk root:
D:\MYAPPNAME\MYAPPNAME\1.0.0
Even if i manually delete the folder, it gets created again when the app runs. What may cause this behaviour?
EDIT
After further investigation, i reproduced the issue using the VS 2017 template for asp-net core2 mvc application.
After adding Microsoft.Extensions.Logging.TraceSource nuget package and configuring the logs in app.config the unwated folder gets created...
This is the relevant part of the App.config
<system.diagnostics>
<sources>
<source name="TestApp" switchValue="All">
<listeners>
<clear />
<add name="RotatingFileLog" />
</listeners>
</source>
<source name="Microsoft" switchValue="All">
<listeners>
<clear />
<add name="RotatingFileLog" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="RotatingFileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" logFileCreationSchedule="Daily" traceOutputOptions="DateTime" BaseFileName="test" location="Custom" CustomLocation="E:\logs\test\" Delimiter="|" AutoFlush="True" Append="True"></add>
</sharedListeners>
<trace autoflush="true" indentsize="4">
<listeners>
<clear />
<add name="RotatingFileLog" />
</listeners>
</trace>
</system.diagnostics>
It has turned out that Microsoft.VisualBasic.Logging.FileLogTraceListener was creating the folder. I switched to another listener, in this case Essential.Diagnostics.RollingFileTraceListener
my works based on a azure web site using client certificate authenticate. it work with old cert. and i applied for a new cert and add it into request. but when request arrived Azure web role side. nothing can retrieved from request, my own code is not executed and return 403 directly.
i guess there is a issue with cert? i installed the cert in local machine, it work well in local. and install it into azure with .pfx and password. no change happened.
there is any other operates when install cert into azure?
does anyone can help me? pls
You need to share more details on what the exact error is. Start by figuring out, what the sub status code really is? whether it is 403.7 or 403.13 or something else
You can enable the logging for the site hosted on the web role and check what is the sub-status code (403.??).
Also you mentioned that the client is an Azure Web Site, so I guess you can enable System.Net tracing to gather more details and share it here. Add the following on the client web app's web.config.
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Http">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.HttpListener">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.WebSockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="System.Net" type="System.Diagnostics.TextWriterTraceListener" initializeData="D:\home\LogFiles\System.Net.trace.log" traceOutputOptions = "ProcessId, DateTime" />
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
<add name="System.Net.Sockets" value="Verbose" />
<add name="System.Net.Http" value="Verbose"/>
<add name="System.Net.Cache" value="Verbose" />
<add name="System.Net.HttpListener" value="Verbose" />
<add name="System.Net.WebSockets" value="Verbose"/>
</switches>
<trace autoflush="true"/>
</system.diagnostics>
</configuration>
I created a webapi project and have used the following in the webconfig
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5" />
<trace enabled="false" localOnly="true" pageOutput="false" writeToDiagnosticsTrace="false"></trace>
<customErrors mode="On"/>
</system.web>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="TestTracer" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Temp\Asptesttrace.log" />
</listeners>
</trace>
<sources>
<source name="Tracing" switchName="TraceSwitch">
<listeners>
<add name="TestTracer"></add>
</listeners>
</source>
</sources>
<switches>
<add name="TraceSwitch" value="0"/>
</switches>
</system.diagnostics>
My WebApiConfig.cs file has the config.EnableSystemDiagnosticsTracing(); to enable tracing
In my class file I am calling the Trace class as shown, to log the method
public void GetTipDetails()
{
System.Diagnostics.Trace.TraceInformation("Entering method - GetTipDetails");
}
Now, I want the user to enable or disable the trace using Webconfig. How do I do it?
I had implemented the Windows Azure Auto Scale Application Block in console application which monitor the performance counters and add the instances to the web role. I implemented the logging also but it does not show me the logs in the console and it does not adding the new instances to the web role based on rules.
And it is not giving me any error...
Without knowing how the application is configured (in particular the content of app.config and of the schedule file), the best educated guess I can make is that your app.config is missing the configuration in <system.diagnostics> to enable the logging of messages from the block.
In short, in your app.config you should have a section similar to the following (taken from one of my sample applications):
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="Autoscaling General" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="FileLog"/>
<remove name="Default" />
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
<source name="Autoscaling Updates" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="FileLog"/>
<remove name="Default" />
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information"/>
<add name="SourceSwitch" value="Verbose, Information, Warning, Error, Critical"/>
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" location="ExecutableDirectory"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
You can find further information from MSDN.
In addition to his, I recall that I had to set some breakpoints (on Autoscaler.Start if I remind correctly) in order to catch some configuration errors.
I want to autoscale my azure worker role based on the length of an azure queue. According to all the documentation I've seen this should be very straightforward, using the queueLength operand.
I've implemented the autoscaler, uploaded it to my service and added a bunch of elements to my queue, but the number of instances are not increasing.
What's the best way of troubleshooting? I've remote desktopped to the role and there isn't anything in the event log. Is there a log of autoscaling events/errors I can check?
Edit:
When I run the app in my dev environment, I see that the autscaler has successfully loaded the ServiceInfo.xml. There is a queue entry and a role entry. However, the rules don't appear to have been loaded out of the rules.xml file.
More edit:
When I removed the reactiverules and operands nodes from the rules.xml file, the constraint rule loads successfully. So the problem is in one of those nodes.
My serviceinfo xml file:
<?xml version="1.0" encoding="utf-8"?>
<serviceModel xmlns="http://schemas.microsoft.com/practices/2011/entlib/autoscaling/serviceModel">
<subscriptions>
<subscription name="MySubscription" subscriptionId="blah" certificateThumbprint="‎blah" certificateStoreName="My" certificateStoreLocation="CurrentUser">
<storageAccounts>
<storageAccount alias="targetstorage" connectionString="DefaultEndpointsProtocol=https;AccountName=blah; AccountKey="blah">
<queues>
<queue alias="auditqueue" queueName="auditqueue"/>
</queues>
</storageAccount>
</storageAccounts>
<services>
<service dnsPrefix="blah" slot="Production" scalingMode="Scale">
<roles>
<role alias="ScalingWebRole" roleName="ScalingWebRole" wadStorageAccountName="targetstorage" />
</roles>
</service>
</services>
</subscription>
</subscriptions>
</serviceModel>
My rules xml file:
<constraintRules>
<rule name="Default" enabled="true" rank="1">
<actions>
<range target="ScalingWebRole" min="1" max="10" />
</actions>
</rule>
</constraintRules>
<reactiveRules>
<rule name="Scale up when queue is long" enabled="true">
<actions>
<scale target="ScalingWebRole" by="1" />
</actions>
<when>
<greaterOrEqual operand="QueueLength_Avg" than="5" />
</when>
</rule>
<rule name="Scale down when queue is short" enabled="true">
<actions>
<scale target="ScalingWebRole" by="-1" />
</actions>
<when>
<less operand="QueueLength_Avg" than="5" />
</when>
</rule>
</reactiveRules>
<operands>
<queueLength alias="QueueLength_Avg" aggregate="Average" queue="auditqueue" timespan="00:01:00" />
</operands>
</rules>
Wasabi publishes a lot of diagnostic information, but you have to enable it. In the role where you are hosting the autoscaler, update the app.config to include the following:
<system.diagnostics>
<sources>
<source name="Autoscaling General" switchValue="All">
<listeners>
<add name="AzureDiag" />
</listeners>
</source>
<source name="Autoscaling Updates" switchValue="All">
<listeners>
<add name="AzureDiag" />
</listeners>
</source>
</sources>
<sharedListeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiag"/>
</sharedListeners>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
Then, if your role is configured to upload the log entries to the WADs table (Windows Azure Diagnostic table), you will see the entries there.
More info about the log entries that Wasabi generates here.
With the assistance provided by the diagnostics (thanks #Julian Dominguez), it became clear that the first time the autoscaling block was trying to hit the service (to check the queue length), it was failing. This is because the system was looking for the certificate in the CurrentUser store rather than the LocalMachine store.
Once I changed that setting in the configuration, it started to work.