CsharpGears is Free and Open Source Framework



I use this opportunity to emphasize the fact that the CsharpGears Framework is absolutely Free and Open source, meaning anyone who wants can download the framework and use it for free, or even make changes in the code, but he/she can't claim he/she invented it.
Recently a reader told me he wanted to use my framework but he was interested in making changes in the source code, and then I noticed that I havent put the full version available for download, so I did that immediately.
And anyone who has some kind of trouble using the CsharpGears framework, may feel free to contact me, I will be happy to help. If anyone has a constructive suggestion or wish for next releases, post it as a suggestion.

"There is nothing like a dream to create the future" - Victor Hugo

C# RSS Builder : How to Build Really Simple Syndications



RSS has become quite popular recently, and from developer's point of view, it's a quite common requirement to implement. So I have decided to make an object-oriented approach and write a few classes that might come in handy. You can see the source code below, it is quite simple and straightforward. One note to those who haven't read my previous posts: The retrieval from the database is made by another set of classes called DatabaseEntities. These classes allow me to directly bind C# classes with SQL table columns and return lists of business objects instead of DataTables.
Back to the RSS feed, there are a few things you need to do: first you need RSS items, as by the standard of the RSS XML tags. Then you need to create a logo of the RSS feed. This is optional, but it is a nice way to offer your readers visual connection to your brand. You will also need a Stream object where the feed should be output. It could be any type of stream. For the purposes of this example, I am using a FileStream, but for a real scenario (ASP.NET) you would need to use the Response's output stream. Take a look at the code, and please tell me if it is REALLY SIMPLE :)


C# Logger when Handling Exceptions

Having the Logger configured as in the previous post, it is very easy to use it to log exceptions directly. The ILogger interface provides a method called AppendException() which takes a reference of an Exception object, which will log the stack trace, the message and the targetted site of the exception that was thrown. If you are familiar with my previous post, you can use this class from the CsharpGears framework to log your exceptions out-of-the-box. For instance, in ASP.NET web applications, you could use this logger to trace all the exceptions in the global.asax file when handling the event OnApplicationError or anytime an exception occurs and then redirect the user to a custom error page.

Here is the minimum amount of code to set all that up:

/* Set up configuration for the logger */
            string DbProvider = "System.Data.SqlClient";
            string ConnectionString = "...";

            /* Create the logger */
            ILogger Logger = new DbLogger(DbProvider,ConnectionString);
            Configuration.LogLevel = LogLevel.ERROR;

            try
            {
                /* Generate an exception */
                int generates_exception = 1 / 0;
            }
            catch (Exception ex)
            {
                Logger.AppendException(ex);
            }
            /* Retrieve the messages from today */
            List<LogMessage> TodaysLogContent = Logger.ReadLogByDate(DateTime.Now);

            /* Print the log messages from today */
            foreach (LogMessage message in TodaysLogContent)
            {
                Console.WriteLine(message.Message + " " + message.UserName + " " + message.Date + "\n");
            }

Creating C# Logger with CsharpGears



The Need of Logger for C#
Loggers come in handy when one wishes to trace the execution of his program. These pieces of code make life much easier when it comes to maintaining the application code error free. That is because with logging capabilities, the developer is able to track every time an unusual event occurs. Then it will be easy to determine where the code needs more attention, whether it includes refactoring, bugs or something else.
There are loggers for C#, they are not something new. But what they often lack, is known as ease-of-use. Here could fall Log4Net and other classes that could be found accross the Web. Often, developer needs a simple logger, some code that will get the job done when an exception is thrown. 
Therefore I have decided to write flexible C# classes that will still be extremely simple to use, flexible by design, and will give the developer control of the log level.(Log levels are an important aspect of the loggers, as they give the power to control which events will enter the log, and which will be left out.
The Database Logger in C#
The Logger classes in the CsharpGears Framework are organized in the following way: