I can see that ABP logs all errors in the log.txt file in the but wonder if there is any tutorial that explains how to add ELMAH to the Boilerplate template?
I am using Asp core + Angular template. I have already installed Elmah to my solution but not quite sure how to integrate AbpHandledExceptionData with it.
Here are my settings:
//ELMAH
services.AddElmahIo(o =>
{
o.ApiKey = _appConfiguration["Authentication:Elmah:APIKey"];
o.LogId = new Guid(_appConfiguration["Authentication:Elmah:LogId"]);
});
You can refer Logging from ASP.NET Core. Another option similar to ELMAH (and ELM) is Glimpse: http://getglimpse.com/
You can also use ASP.NET Core Diagnostics for the same purpose.
Related
I am using Swagger in an ASP.NET MVC WebAPI project. This project has Swashbuckle nugget package installed and generates Swagger UI and Swagger/docs/v1. A consistent problem I'm having is developers will break the swagger file by not carefully naming their webAPI operations. I would like to add a unit test to prevent me from finding out that swagger/docs/v1 isn't available by going to the Swagger UI site after deployment and seeing an HTTP 500 displayed in the swagger UI. Does anybody know how to write a unit test to validate that Swashbuckle can successfully generate the swagger docs?
Found a great way to do what I want:
[Fact]
public async Task TestSwagger()
{
var webHostBuilder = new WebHostBuilder()
.UseEnvironment("Test") // You can set the environment you want (development, staging, production)
.UseStartup<Startup>(); // Startup class of your web app project
using (var server = new TestServer(webHostBuilder))
{
using (var client = server.CreateClient())
{
string result = await client.GetStringAsync("/swagger/v1/swagger.json");
JObject root = JObject.Parse(result);
}
}
}
This uses the following nuget package:
Microsoft.AspNetCore.TestHost
Look at the UnitTests we have on Swashbuckle :
https://github.com/domaindrivendev/Swashbuckle/tree/master/Swashbuckle.Tests/Swagger
I'm sure one of those is really close to what you are looking for.
...But if is just the naming of the webAPI operations you could just loop over those using GetApiExplorer and make sure they follow your rules
To whom may be looking for a Asp.Net Core Swagger testing solution, I suggest taking a closer look at Cristophe Blin's aproach
Is it possible to configure ELMAH with ASP.NET vNext? If so, how?
I am lost as to where even start, given there's not even a web.config anymore. If anyone has or can figure it out, please share with us.
Thank you
ELMAH does not work with ASP.NET 5 because ELMAH (given its name) is based on ASP.NET 4.x's Modules and Handlers (the "MAH" of "ELMAH").
In ASP.NET 5 the replacement for modules and handlers is called middleware.
There is a prototype in ASP.NET 5 called "ELM" (Error Logging Middleware) that has some features similar to ELMAH. You can check out a sample here: https://github.com/aspnet/Entropy/tree/dev/samples/Logging.Elm
I am using MVC 3 with SQL Server 2008 R2 DB.
I installed elmah 1.2.2 and SQL Server script.
Might anybody have some detailed information on how to setup Elmah with SQL Server 2008.
I checked online but could not find detailed information.
Since you have already run the SQL Server setup script and installed Elmah in your MVC application, you should just need to add the following to your web.config to have Elmah send its logs to your sql server instance.
<elmah>
...
<errorLog type="Elmah.SqlErrorLog, Elmah"
connectionStringName="<definedConnectionString>"
applicationName="MyAppName"/>
...
</elmah>
Keeping in mind that you will need to replace "<definedConnectionString>" with the name of the connection string that points to your SQl 2008 instance from your <connectionStrings> section of your web.config.
I would also recommend reading through the following 5 part series: Logging Errors with ELMAH and MVC 3, it contains a lot of great recommendations for using ELMAH with MVC. Also you might consider using installing the Elmah.MVC NuGet Package to change the default behavior of Elmah within an MVC application.
The application includes:
ASP .NET MVC web app
DAL
Background Service
Library project
The web app and background service projects use the library project to send emails. SMTP settings are included in a config file in the library project itself.
In this scenario, is there a way to bind ELMAH to pick up SMTP settings from the library project? Perhaps if there's a way to configure ELMAH through code (during Application_Start), it would help achieve what's intended.
Guidance much appreciated.
You might find some use out of [this article].
Particularly the section about sending error reports automatically through email might be useful for you. Here's a more focused link with the same topic: [link]
Although these show how to setup a static address for your SMTP settings, I'm not sure I know how to dynamically create them at run-time based on a config file. If I find a way to do this in a better way I'll be sure to edit this answer or post a comment, but take a look at the links to see if they help for now.
You can configure elmah to post the error report to an HTML address. See this article.
When you set it to post to that address, you can have whatever back end you want catch it and send the email for you.
You mentioned you're using MVC, so you could have elmah post to a controller action that would then send the email, using the SMTP settings from your library project since you'd have access to the references there.
I don't want WCF, I only want web service.
Thank you.
They've obscured it, but it's easy enough:
Right-click on your solution, select Add New Project.
In the Framework selection dropdown, select .NET Framework 3.5
Select the Web installed templates listing and you'll find ASP.NET Web Service Application as the last one in the list.
In other words, you can create one in .NET 3.5, but not 4. Now, that being said, it seems like it may be possible to create a .NET 4 template for VS2010, but I'm not a VS2010 guru, so that's for someone else to elaborate on.
Edited to Add: Somebody else posted a response to your question that was also a good answer, I thought, but they deleted it themselves for some reason. I don't remember their user name. I'll repeat it here.
If you create a new Web Application in the solution, you can then Add New Item, and one of the options under Web is "Web Service" at the very bottom.
The only drawback to this is that besides the web service, you also have the usual default items for a web application, namely default.aspx, about.aspx, global.asax, and site.master, as well as the folders Account, Scripts, and Styles. But you can delete these, so no problem. Also keep in mind that the web.config in the Web Application project will be different from that of the Web Service, and that the assembly bindings for the web service will point to ASP.NET v2 & v3.5 (see its web.config), whereas the service in the web application project will default to ASP.NET v4 (through its project file). I don't know if any negative implications exist for either way of working, though I suspect that both will work just fine.
If you select the framework like mentioned above to 3.5 you can select a web service application. If you want it to be targeted at .NET 4.0 framework, go into my project --> Compile --> Advanced Compile Options --> change the target framework to .net framework 4.
You can also change your compile options to target it at a x64 or x86 (32 bit) server.
web.config in the Web Application project will be different from that of the Web Service, and that the assembly bindings for the web service will point to ASP.NET v2 & v3.5 (see its web.config), whereas the service in the web application project will default to ASP.NET v4 (through its project file). I don't know if any negative implications exist for either way of working, though I suspect that both will work just fine.
Here was my resolution:
Right-click on your project name and select to Add Service Reference.
Select the Advance button at the very bottom.
Select the Add Web Reference button at the very bottom.
Proceed as usual. :)