Enable \ Disable C# Tracing Not working - c#-4.0

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?

Related

Errors logged in ELMAH_Error table not showing on elmah.axd page

Need some help figuring out why my instance of Elmah is not showing errors logged in the DB table on the elmah.axd page. It seems like everything is configured correct, including 'applicationName', but nothing shows in the UI. Please see the setup code below.
Web.config
<configSections>
<sectionGroup name="elmah">
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
</httpModules>
</system.web>
<system.webServer>
<handlers>
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</handlers>
<modules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
</modules>
</system.webServer>
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah"
applicationName="InfoEx"
connectionStringName="MyConnectionString" />
<security allowRemoteAccess="false" />
</elmah>
ELMAH_Error Table
Elmah.axd

Azure Diagnostic - Output TraceSource to Log Stream on Azure Portal

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>

cert missing when request arrive Azure web role

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>

elmah.axd not found on IIS 8.0

Ok..I know this is asked many times and I looked bunch of questions and answers about this and nothing worked for me and I am getting crazy. I am trying to put elmah to my asp.net mvc 5 application and I can't get it to work. I keep getting not found error.
My config for elmah is:
<appSettings>
<add key="elmah.mvc.disableHandler" value="false" />
<add key="elmah.mvc.disableHandleErrorFilter" value="false" />
<add key="elmah.mvc.requiresAuthentication" value="false" />
<add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
<add key="elmah.mvc.allowedRoles" value="*" />
<add key="elmah.mvc.allowedUsers" value="*" />
<add key="elmah.mvc.route" value="elmah" />
</appSettings>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
<system.web>
<customErrors mode="On"></customErrors>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</handlers>
<modules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<!--<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />-->
</modules>
</system.webServer>
<elmah>
<security allowRemoteAccess="1" />
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/elmah" />
</elmah>
and yes i have ignored .axd in my rout config..
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
What am I missing ??
You need to create a MIME type for that extension in IIS:
To define a MIME type for a specific extension, follow these steps:
Open the IIS Microsoft Management Console (MMC), right-click the local computer name, and then click Properties.
Click HTTP Headers.
Click MIME Types.
Click New.
In the Extension box, type the file name extension that you want (for example, .axed)
In the MIME Type box, type application/octet-stream.
Apply the new settings. Note that you must restart the World Wide Web Publishing Service or wait for the worker process to recycle for the changes to take effect. In this example, IIS now serves files with the .axed extension.

Is it possible to use ELMAH in a SharePoint environment?

Has anyone integrated ELMAH into their SharePoint environment?
I suppose it's possible as it's all ASP.net, but I just wondered if anyone had done it and if there's a walk through on how to achieve it?
One thing that IS important when setting up ELMAH, or most HTTPModules in Sharepoint is that they need to be at the beginning of the httpModules section. Otherwise SharePoint will essentially swallow the exception and ELMAH functionality will not be invoked
Works
<clear />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
<add name="SPRequest" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
... Rest of SharePoint modules....
Does not work
<clear />
<add name="SPRequest" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
... Rest of SharePoint modules....
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah"/>
We use ELMAH in our MOSS 2007 environment. Since ELMAH uses HttpHandlers and is set up via the web.config, activating it was a cinch. Just add the ELMAH stuff to the web.config for the application that you're running inside SharePoint.
If you want ELMAH to report errors at a level higher than your custom application, then add it to the SharePoint web.config.
There is no magic to it, just hook it up like you would on any other ASP.NET site.
Following are the config entries that needs to added in web.config of the SharePoint web application
Add under configsection
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
Add connectionstring section
<connectionStrings>
<add name="elmah-express" connectionString="Data Source=[server name];Initial Catalog= [ELMAH_customlogging];User ID=testuser;Password=Welcome1;" />
</connectionStrings>
Add elmah section just below the connectionstring section
<elmah>
<security allowRemoteAccess="0" />
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-express" />
</elmah>
Add handler and module entry in httphandlers and httpmodules section under system.web
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
</httpHandlers>
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
Add handler and module entry in handlers and modules section under system.webserver
<modules runAllManagedModulesForAllRequests="true">
<remove name="ErrorLog"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
<add name="ErrorTweet" type="Elmah.ErrorTweetModule, Elmah" preCondition="managedHandler" />
</modules>
<handlers>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
Please refer below link for elmah implementation in sharepoint
http://sidteche.blogspot.in/2014/08/implement-elmah-custom-logging-in.html

Resources