Вопрос

When I worked with Java, I used log4j and slf4j in my web projects. I used next scheme:base class for objects, where I can use inheritance, and static class for other situations.

Now I have project on C#(MVC3). What are the best practices for error logging in C# web applications?

Это было полезно?

Решение

Have a look at log4net. It's similar to log4j (as far as I know) and we're using it all time. It has the ability to be configured via app.config and holds a variety of possibilities to write your logs to (file, rolling file, database, etc.).

Tip: Avoid writing your logs on a network share. We've tried this and we experienced some huge slow-downs for our entire application with this strategy.

Другие советы

I'm surprised that ELMAH is only mentioned in a comment so far. Frank may be familiar with log4j, why log4net may be an obvious choice. Be he is also asking what's the best practices for error logging in C# web applications. ELMAH is the de facto standard error logging component for .NET web applications (Microsoft themselves uses ELMAH as an example in pretty much everything they write about error logging in web applications).

I've written an ELMAH Tutorial, which show you how to get started.

Also if you've already fallen in love with log4net (nothing wrong with that), there's a log4net appender for ELMAH.

I'd say Microsoft Enterprise Library.

http://msdn.microsoft.com/en-us/library/ff648951.aspx

it's easy to use, has many features (like db logger, flat file logger, send to e-mail ...)

Use http://logging.apache.org/log4net/
read this article Log4net is very simple to use yet powerful logging option. This article describes log4net usage in a web application in six easy steps.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top