log4net not working using log4net appender azure in MVC applcation - asp.net-mvc

same log4net appender azure nuget code working fine for console app,
but not working in MVC application.
I'm using this nuget log4net.Appender.Azure 1.1.1
already added log4net.Config.XmlConfigurator.Configure();
in Global.asax
web.config
<log4net>
<!-- Azure Table Appender, uncomment, set proper QueueName and AWS credentials (appSettings) to try it out -->
<appender name="AzureAppender1" type="log4net.Appender.AzureTableAppender, log4net.Appender.Azure">
<param name="TableName" value="test" />
<param name="ConnectionString" value="***" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
Can anyone know why it is not working ?

I am not sure - but I would be a little careful about using Tables for large scale logging scenarios. Take a look at the logging anti-pattern in this Table Design Guide. It can often lead to hot partitions - and often times the scenario is much better supported using Blobs.

Here we go I found that it is problem od log4net dll version.
in nuget log4net appender azure version of log4net dll is 1.2.12 it is the older one. need should be updated to newer version 1.2.13
that solves the above issue.

Related

How to use Azure storage for elmah logs instead of elmah logs in SQL Server database

Currently in my project, I am logging exceptions by using elmah in a separate table in SQL Server. Is it possible to store these elmah exceptions in Azure storage only, not in SQL Server? Since I do not want to log errors in my database.
//web.config
<elmah>
<security allowRemoteAccess="1" />
<errorLog type="Elmah.SqlErrorLog, Elmah"
connectionStringName="DatabaseConnectionStringName" />
</elmah>
Currently in my web.config, I configure for elmah logs in SQL Server.
Set allowRemoteAccess = 1 and added errorlog type as Elmah.SqlErrorLog. Can
anyone help?
Thanks in advance.
It is possible, we can store elmah exceptions in Azure table storage.
We need to use this package: Elmah.AzureTableStorage.
We can install this via VS Package Manager:Install-Package Elmah.AzureTableStorage -Version 1.0.0.
In web.config, we can set as below:
<errorLog type="Elmah.AzureTableStorage.AzureTableStorageErrorLog, Elmah.AzureTableStorage"
connectionStringName="ElmahAzureTableStorage" />
I have tested and the screenshot of my log in table storage for your reference:
More information for your reference:
GitHub: Elmah.AzureTableStorage
ELMAH on Azure Table Storage

How to configure local DynamoDB as ASP.NET session state provider

I have been tasked to write a proof of concept for using Amazon's DynamoDB service to store ASP.NET session state. I downloaded Amazon's local DynamoDB server from here, and got it running successfully. I created a test MVC website, and added the following NuGet packages.
<package id="AWS.SessionProvider" version="3.1.0.2" targetFramework="net461" />
<package id="AWSSDK.Core" version="3.1.4.3" targetFramework="net461" />
<package id="AWSSDK.DynamoDBv2" version="3.1.4.0" targetFramework="net461" />
I added the following to web.config.
<sessionState mode="Custom" customProvider="DynamoDB">
<providers>
<add name="DynamoDB" type="Amazon.SessionProvider.DynamoDBSessionStateStore" AWSProfileName="" Region="" />
</providers>
</sessionState>
Now I'm stuck. Amazon's documentation for local DynamoDB only talks about defining the service URL, not profile or region settings. Amazon's documentation for the session provider only talks about using a real online DynamoDB service with real credentials. The only mention I can find online of setting the service URL assumes that you are creating a DynamoDB client in code for arbitrary data access. I can't seem to find any overlap between these three concepts. Can anyone tell me how to configure local DynamoDB only as a session provider without referencing real Amazon credentials or regions?
Set the attribute ServiceUrl="http://localhost:8000/"
<sessionState timeout="20" mode="Custom" customProvider="DynamoDBSessionStoreProvider">
<providers>
<add
name="DynamoDBSessionStoreProvider"
type="Amazon.SessionProvider.DynamoDBSessionStateStore"
AWSProfileName="default"
AWSAccessKey="must be real"
AWSSecretKey="must be real values"
Region="eu-west-1"
ServiceUrl="http://localhost:8000/" />
</providers>
</sessionState>
Source:
https://github.com/aws/aws-dotnet-session-provider/blob/master/src/DynamoDBSessionStateStore.cs#L87

500.22 for subdirectories files on root ASP.NET application with child virtual directory ASP.NET MVC application

I'm trying to put together the following architecture:
/ (root): ASP.NET WebForms 4.6 application.
/SPA (virtual directory): ASP.NET MVC 4.6 application.
To make things clear, here is the IIS Express configuration:
<site name="Redacted.Axis.Web.UI.SingleApp-Site" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\Axis\Dev\PocInternational\Web\Redacted.Axis.Web.UI.App" />
</application>
<application path="/SPA" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Projects\Axis\Dev\PocInternational\Web\Redacted.Axis.Web.UI.SingleApp" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:4010:localhost" />
</bindings>
</site>
They are on separated web projects (UI.App and UI.SingleApp). I want them to share the same authentication. I managed to make that work already with common machine keys and same authentication/forms configuration.
My last problem is, static files under the root application are not being served, like /CSS/site.css or /JS/jquery.js. I'm getting 500.22 error for all of them.
This error is suppose to mean I should be in classic mode, but WebForms app worked fine so far in integrated mode (and default.aspx or login.aspx at root work).
It can also means that some modules defined in system.web are not in system.webServer. But they are.
I have this in both web.config files:
system.webServer/validation#validateIntegratedModeConfiguration=false
systel.webServer/modules#runAllManagedModulesForAllRequests=true
Static files for sub MVC application work fine, like /SPA/Content/sites.css.
The WebForms application worked fine before I added the virtual directory with the MVC application. Only other thing I had to change was adding location#path=.#inheritInChildApplications=false on all web.config nodes of root application so the MVC web.config works correctly.
There must a little thing off but I can't put my finger on it...
Power of posting.
I started to think my location tags in root web.config had something to do with it.
I found the answer here.
For the lazies, validateIntegratedModeConfiguration has to be outside the location tag. You can have two system.webServer section, it doesn't matter (but not two validation tags).
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<location path="." inheritInChildApplications="false">
<system.webServer>...</system.webServer>
</location>

VS2010 ASP.MVC breakpoints not being hit in multiple site solution

I am writing a Federated web solution it has multiple projects. Debugging has been working fine until yesterday when suddenly (I don't recall messing with anything critical) I got the 'breakpoint will not currently be hit. No symbols have been loaded for this document' message on my 3 ASP.MVC projects in the solution.
I trawled around the web and this site for advice and these are the things I have done.
checked build > configuration manager for correct build setting
checked project > properties to ensure ASP.Net ticked for debuggers
checked Web.config to ensure 'compilation debug="true" targetFramework="4.0"'
iisreset
deleted bin & obj directories in each project
clean and rebuild the solution
deleted the contents of
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files'
exited and restarted VS2010
cried like a baby
After doing these things 2 of the 3 ASP.MVC projects are debugging properly, but the 3rd and critically the one I actually want to step through is not.
other info for you
using locally install IIS (not IIS express)
Windows 7
VS2010 with all service packs
ReSharper is installed
Chrome is the Browser I'm using
Any help appreciated.
This may be obvious, but it wasn't in your list of things you've done and in a state of panic can get forgotten, but have you checked the the Directory in IIS is the same as the one the code VS has loaded?
VS should recreate the site (depending on project settings), so try closing VS, deleting the site, reopening the project and letting VS recreate the IIS site for you.
I have worked out what the problem is.
While I had the initial problem of all projects not debugging the federation project turned out to be a special case. I have been away on leave and had forgotten that I had this in my web config
<federatedAuthentication>
<!--
<wsFederation passiveRedirectEnabled="false" issuer="https://localhost/FederationProvider/"
realm="https://localhost/Application/Home/FederationResult" requireHttps="true" />
-->
<wsFederation passiveRedirectEnabled="false" issuer="https://localhost/Issuer/"
realm="https://localhost/Application/Home/FederationResult" requireHttps="true" />
<cookieHandler requireSsl="true" path="/Application/" />
</federatedAuthentication>
When I changed it so I am using the federator rather than the issuer directly the debugger works.
<federatedAuthentication>
<wsFederation passiveRedirectEnabled="false" issuer="https://localhost/FederationProvider/"
realm="https://localhost/Application/Home/FederationResult" requireHttps="true" />
<!--
<wsFederation passiveRedirectEnabled="false" issuer="https://localhost/Issuer/"
realm="https://localhost/Application/Home/FederationResult" requireHttps="true" />
-->
<cookieHandler requireSsl="true" path="/Application/" />
</federatedAuthentication>
I feel pretty stupid for not realising this earlier. VS2010 was just being too smart.

Anyone know how to turn off debugging / Logging in DotNetOpenAuth

I just setup a logging provider using Log4net and noticed when testing that DotNetOpenAuth is logging messages as well. They must be using log4net as well, great I don't want 50 inserts everytime someone logs in with an openID..
Anyway to turn this off?
Yes.
<configuration>
<log4net>
<logger name="DotNetOpenAuth">
<level value="ERROR" />
</logger>
</log4net>
</configuration>

Resources