How to get ELMAH to log to Mongodb? - asp.net

i want to use Elmah to log errors into my mongodb database
i am using Asp.net mvc website
i have done following steps already
1.installed Elmah from nuget solution
and it successfully log erros in Elmah.axd page
now all i want is to log this errors in my mongodb database
can some one suggest me steps for that ?

You can use the elmah-mongodb package. Install the elmah.mongodb NuGet package and add the following to your web.confing file:
<elmah>
<errorLog type="Elmah.MongoErrorLog, Elmah.MongoDB" connectionStringName="elmah-mongodb" maxSize="10485760" maxDocuments="10000"/>
</elmah>
<connectionStrings>
<add name="elmah-mongodb" connectionString="mongodb://localhost/elmah?w=0"/>
</connectionStrings>

Related

IIS (There was an error while performing this operation)

I receive There was as error while performing this operation error referring to web.config. I follow below configuration:
OS is Windows server 2012 R2 with IIS version 8.5.
URL Rewrite 2.1 module is installed on the machine.
IIS_IUSRS has full access to the directory.
Application Initialization module is installed
.Net CLR Version v4.0.30319 and managed pipeline mode is integrated.
IIS configuration is as below:
Web config is as below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MES.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: e8701310-485f-4f88-b7d0-1473d07238ac-->
browsing the page I receive below message:
However, when I remove
<aspNetCore processPath="dotnet" arguments=".\MES.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
from web.config I don't receive (There was as error while performing this operation) error but I get below error:
This error occurred for me when trying to double-click on the Logging module for any site with a bad Web.config.
"Bad" includes Web.configs that just have a module IIS doesn't understand - in my case, IIS 10 couldn't understand the <rewrite> tag, and exploded with this extremely confusing error.
You can verify this by just commenting out the contents of your Web.config. The error goes away - then just gradually reduce how much is being commented out until you find the culprit, and track down that solution.
Add <aspNetCore> back and also install ASP.NET Core module on this machine,
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/aspnet-core-module?tabs=aspnetcore2x
I also wrote a tool to better automate such detection,
https://www.jexusmanager.com/tutorials/oob-500.html
This error is typically caused by a reference inside the web.config which cannot be resolved by the dotNet runtime.
If you are using dotNet core, AND you installed the dotNet core hosting bundle BEFORE you configured your server to run IIS you may get this error.
To fix it in this case, you need to re-run the dotNet core hosting bundle installer AGAIN, in "repair mode"
As described in the box entitled "Important", here.
I had this problem with .NET Core 2.1.
I installed 2.1 SDK (v2.1.301) and as Microsoft says Hosting Bundle now installs with SDK, but in my case this did't work.
This problem disappeared only when I installed 2.1 Runtime (v2.1.1) for Hosting Bundle Installer.
Maybe you need to install URL Rewrite
I had same problem.

VSTS Build With Local Nuget Package From Local Nuget Server

Has anyone had success building an ASPNET5 application in VSTS with a local (not public facing) Nuget server as a feed? Following these steps: https://msdn.microsoft.com/Library/vs/alm/Build/azure/deploy-aspnet5 I can see the script restoring but it always errors out on my local package. I am sure I am configuring something wrong. This is what I have tried:
Add a Nuget Installer task with a arg to my solution and NuGet arguments nugete.exe -source "https://www.nuget.org/api/v2/;http://mynugetserver" (and I tried including no Nuget arguments and including a Nuget.config in the root of my solution). However, the build runs into a an exception saying it cant find the local url: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The remote name could not be resolved: 'mydomain'. Okay I understand that, but I do I get it to recognize a local URL?
After researching I thought I would have to use the Package Manager Extension for VSTS. So I loaded my packaged on there successfully, but when I included that package URL in my Nuget.config I get a bunch of unauthorized responses from the PreBuild.ps1 because it is trying to look at the VSTS package URL too. And that is where I am now.
Current Nuget.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<config>
<!--DO I NEED TO INCLUDE MY PROXY INFOR HERE I AM BEHIND ONE AT WORK-->
</config>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<activePackageSource>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</activePackageSource>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Local" value="https://vstsurl/DefaultCollection/_packaging/Local/nuget/v3/index.json" />
<add key="Company Nuget Gallery v2" value="http://mydomain/nuget/api/v2" />
</packageSources>
</configuration>
UPDATE
if I use the Package Manager on VSTS these are the warnings / exceptions all which seem to come from the local feed. not sure why it is using the local feed for all the external packages
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
... other exceptions here
----------
Restore failed
If you are using the build agent hosted by VSTS and your nuget server is in local (Cannot access from internet), the package restore will fail since the build agent cannot find your nuget server. You'd either configure your nuget server so that it can be accessed from internet or deploy your own build agent in the same intranet with your nuget server.

Wix setup failing with error 1603

I have written a .NET 4 desktop application and when trying to run the Setup.exe I am getting the following error in the log file.
I am using Visual Studio 2012 with Wix 3.7.
MSI (s) (E8:1C) [16:51:54:890]: Invoking remote custom action. DLL: C:\windows\Installer\MSIFECD.tmp, Entrypoint: EncryptConfig
SFXCA: Extracting custom action to temporary directory: C:\windows\Installer\MSIFECD.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action SecureConfig!SecureConfig.CustomActions.EncryptConfig
EncryptConfig: Begin
An error occurred creating the configuration section handler for security: Could not load file or assembly 'Order.Configuration.Net' or one of its dependencies. The system cannot find the file specified. (C:\Program Files (x86)\Orbit Order System\Orbit Order System.exe.config line 6)
CustomAction EncryptConfigurationFile returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 16:51:55: InstallFinalize. Return value 3.
I can confirm that `Order.Configuration.Net.dll' exists in the target folder as does the application config file.
This is the app.config file:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="backup"
type="OrderConfiguration.BackupConfig, Order.Configuration.Net"/>
<section name="general"
type="OrderConfiguration.GeneralConfig, Order.Configuration.Net"/>
<section name="security"
type="OrderConfiguration.SecurityConfig, Order.Configuration.Net"/>
<-- ** THIS IS LINE 6 **
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<backup configSource="config\backup.config"/>
<general configSource="config\general.config"/>
<security configSource="config\security.config"/>
<connectionStrings>
<clear/>
<add name="OrderDb"
connectionString="Data Source=(local);Initial Catalog=OrbitOrder;
User Id=User;Password=Pass;MultipleActiveResultSets=true;"/>
</connectionStrings>
</configuration>
I also confirm that config\security.config exists in the target folder.
I have spent three hours trying to figure out what the error means as all files actually exist in the target folder. I actually copied the WIX set up from a prior solution that I worked on a year ago and that one works fine without any issues.
The custom action that is failing is trying to encrypt the security configuration section.
I am at a loss to explain why MSI is throwing a 1603 error when there doesn't appear to be anything amiss.
I managed to resolve this after adding the following code to the Wix custom action:
AppDomain.CurrentDomain.AssemblyResolve += ( sender, args ) =>
{
return Assembly.LoadFrom( string.Format( #"{0}Order.Configuration.Net.dll", installFolder ) );
};
This basically says to load the assembly when it encounters a reference that needs resolving.
As per the log, the error is returned by the custom action written by you, so please debug the custom action dll during installation. Easiest method of debugging custom action is to add a message box in the code (begin of custom action) and attach to process in visual studio when the message box is displayed. other way is to use MsiBreak environment variable as described in http://msdn.microsoft.com/en-us/library/aa368264%28v=vs.85%29.aspx

Setup Elmah with MySQL?

I have run the Elmah nuget package, copied the mysql.data.dll to the bin folder and run the mySQL script in the database but where do I state the address and login to the database?
Best regards
If you've already installed Elmah and created the tables in your database all your should need to do now is make sure the tables have the correct permissions then edit the connection string for Elmah in your web.config to include the username and password for whatever account you'll access the DB from the same as any other connection string but using the MysqlClient
In your web.config you should have something similar to:
<elmah>
<errorLog type="Elmah.MySqlErrorLog, Elmah" connectionStringName="Elmah.MySql" />
<security allowRemoteAccess="1" />
</elmah>
And also elsewhere in the connection strings bit something along the lines of:
<connectionStrings>
<add name="Elmah.MySql" connectionString="[STUFF HERE];User ID=[WHATEVER];Password=[WHATEVER];" providerName="System.Data.MySqlClient" />
</connectionStrings>

IIS7 & Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule registering problems

UPDATE:
In Windsor 2.5 the assembly name is Castle.Windsor not Castle.MicroKernel
I'm trying to deploy an ASP.NET MVC app to IIS7 and I'm getting this error:
Looks like you forgot to register the http module
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '' to the section on your
web.config
My httpModules contains:
<httpModules>
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel"/>
</httpModules>
system.webServer handlers section contains
<handlers>
<remove name="PerRequestLifestyle"/>
<add name="PerRequestLifestyle" preCondition="managedHandler" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Microkernel" verb="*" path="*.castle" />
</handlers>
I added the verb="*" path="*.castle" part as I was getting errors when they were missing. Not sure if their values are correct.
Anyone know what the problem is here?
You can solve the problem by registering the HTTP module in configuration/system.webServer/modules instead of configuration/system.web/httpModules.
My problem was that I was bootstraping the container in Application_Start, Modules are not initialized at that point in ASP.NET so when you try to register/use PerWebRequest Lifestyle it throws that Exception because it detects that the module was not initialized.
I ended up using this library from Castle Contrib which provides the HybridPerWebRequestTransient Lifestyle which if not initialized at the moment uses the Transient Lifestyle.
You just have to download the library (as zip is ok) open the Solution and compile it, grab the generated DLL and reference it in your project.
If you are using Castle.Windsor version over 3.0 you will have to remove current reference to it and add the reference to the version you are using (I was using 3.1 and did not have any problems).
This is the code to use the Lifestyle: .LifeStyle.HybridPerWebRequestTransient()
Took me some time to find a solution for this but all I had to was update the dll being referneced in the web.config...
Using Castle.Core and Windsor 2.5.1...

Resources