Looking for perfect logger output

September 26th, 2007

When coding (C#), I often encounter a common problem – which logger would be the best? Maybe log4net, maybe one from Microsoft.EnterpriseLibrary, maybe my own one? The answer is simpler that someone could imagine – this one which can produce clean and nice looking output. A log file is usually read by humans so it’s a must for a logger to produce something that is easy to search through.

I am really pissed off when see a bloated logger with many “fantastic” functions like mail sending, multithreading, thread-safety and many others… whose output looks like vomit. I will not present a sample by courtesy to my friend ;)

But take look at this one below. It’s not a perfect output but isn’t it clear and easy to read?

[DBG] 2007-09-25 12:10:32 - Initialization of an object
[DBG] 2007-09-25 12:10:35 - Loading data
[ERR] 2007-09-25 12:10:35 - System.NullReferenceException: Object reference not set to an instance of an object
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.GetConnectedPorts(BtsCatalogExplorer explorer, String pipelineFullyQualifiedName)
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.RemovePortsUsingPipelines()
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.RemovePipelines()
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.Remove()
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.RemoveNamedModule(String
server, String database, String assemblyName, String assemblyVersion, String
assemblyCulture, String assemblyPublicKeyToken, ApplicationLog log)
[ERR] 2007-09-25 12:10:38 - System.NullReferenceException: Object reference not set to an instance of an object
    at Controls_X_YZ.MethodXYZ(Bar bar) in c:\code.ascx.cs:line 256
[INF] 2007-09-25 12:11:00 - Mail with an error has been sent

What kind of information should be logged in your opinion? Which kind of text formatting do you prefer?

Inheritance, Composition, WTF?

September 20th, 2007

Working with the code is not a piece of cake. Especially when one must read and understand "WTF an author had in mind?"
Every day I encounter good code, crazy ideas, stupid constructions and totally fucked up architecture. Unfortunately, the most common is inheritance used where it should not be. Maybe I am too touchy?

Let's assume that we have an object which should be accessible across a project (or among several classes). Normally it's a good idea to create a singleton / static class and initialize it with specified object. I often encounter another approach... I call it "composition by inheritance". There is a class which has the object as a field / property. Then any other class that can use that object... derive from a base class when this object is placed! It looks like below (do not pay attention for types - it's an example only):

C#:
  1. public class Foo
  2. {
  3.         public object SharedObject = new object();
  4. }
  5.  
  6. public class Bar : Foo
  7. {
  8.     public void DoSomething()
  9.     {
  10.         SharedObject.Consume();
  11.     }
  12. }

And the main question - what do you think about it? In my opinion inheritance does not serve this purpose. It should not be used like that because there is no polymorphism here and potential changes in a base class can have many unforeseen consequences.
Any other pros / cons?

The Road

September 9th, 2007

When a coder is bored, stupid ideas go into his mind. And it happened to me this Sunday.
In polish only - sorry for english readers ;)

http://youtube.com/watch?v=_36ccd4wec4

Games screenshots

September 2nd, 2007

Today I added a small gallery of my games screenshots. You can admire it here

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!

Powered by Rootnode