Archive for December, 2009

Enabling Logging In Your Agatha Service Layer

2 commentsWritten on December 19th, 2009 by
Categories: agatha

As of Agatha 1.0 beta 2, you can now use whatever logging library you prefer.  Agatha now uses the Common.Logging project instead of using a logging library directly.  This means you just need to add a bit of configuration to your service host to enable logging and get that logging information in whatever format or manner you want.  Enabling this is pretty easy, since you just need to follow the standard approaches for configuring Common.Logging, and obviously also for the logging library that you use.  I’m just going to show a short example of using XML in your web.config (or app.config depending on your service host) to get this working.

First, you need to add the configuration section for Common.Logging to the <configSections> element:

    <sectionGroup name="common">

      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />

    </sectionGroup>

    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>

 

As you can see, i also included the definition of my preferred logging library (log4net) in this as well.  In this particular case, your service host needs to reference the following assemblies: Common.Logging.dll, Common.Logging.Log4Net.dll and log4net.dll.

The configuration of the Common.Logging library looks like this:

  <common>

    <logging>

      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">

        <arg key="configType" value="INLINE" />

      </factoryAdapter>

    </logging>

  </common>

 

You need to specify which factoryAdapter that Common.Logging will use, in our case the one for log4net.  If you then configure the INLINE value for the configType key, Common.Logging will just initialize log4net in a way that it will simply use the XML configuration that is also present in your config file.  Again, i’ll point you to the Common.Logging documentation for configuring it for your specific library if you’re using something else. 

In my case, my log4net configuration looks like this:

  <log4net>

    <logger name="Agatha">

      <level value="ERROR"/>

      <appender-ref ref="LogFileAppender" />

    </logger>

 

    <logger name="AgathaPerformance">

      <level value="WARNING"/>

      <appender-ref ref="LogFileAppender" />

    </logger>

 

    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" >

      <param name="File" value="log.txt" />

      <param name="AppendToFile" value="true" />

      <rollingStyle value="Size" />

      <maxSizeRollBackups value="10" />

      <maximumFileSize value="10MB" />

      <staticLogFileName value="true" />

 

      <layout type="log4net.Layout.PatternLayout">

        <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} - %m%n" />

      </layout>

    </appender>

  </log4net>

 

The ‘Agatha’ logger simply logs everything coming from types whose namespace starts with Agatha and that logs at the error level (basically just exceptions caught by the Request Processor) and sends that the LogFileAppender (which simply logs in a log.txt) file.  The ‘AgathaPerformance’ logger specifically logs performance warnings coming from Agatha’s PerformanceLoggingRequestProcessor and also sends it to the LogFileAppender.

And that’s all there is to it.

Trying MonoDevelop On OS X, Part Two

4 commentsWritten on December 19th, 2009 by
Categories: Mono

I played around with MonoDevelop 2.2 beta 1 on OS X a while ago.  Back then i considered it promising, yet unusable due to the fact that writing and editing code was extremely slow.  The Mono project recently released Mono 2.6 and a final MonoDevelop 2.2 release so i figured i’d give it another shot on OS X. 

Installation was yet again a breeze… you’re basically up and running within 5 minutes (depending on the speed of your internet connection for downloading the bits obviously).  And this time, the code writing/editing problems have been solved and you can indeed write code in it.  Instead of trying some silly example in it, i wanted to see if Agatha’s in-process Hello World example would work on Mono.   I downloaded the code, and opened the Examples solution:

1 

This solution contains 2 Silverlight projects, 2 Web Application Projects, some regular .NET class libraries and 2 console projects.  MonoDevelop opened it all without any problems and seemed to recognize the different kinds of projects without problems:

2 

3 

While it may not seem impressive to you, i was glad to see that it correctly determined that the Agatha.Common.Silverlight project is indeed a Silverlight project instead of a regular .NET project.  Because the Agatha.Common.Silverlight needs to have some types that are also present in the Agatha.Common assembly, i used linked files in the Agatha.Common.Silverlight project to include those types in the Silverlight assembly.  MonoDevelop nicely picked up on that, and even seems to play more nicely with linked files than Visual Studio does:

4

After that i wanted to change the code formatting options to the settings that i prefer.  In the beta 1 version that i tried earlier, there were plenty of formatting options that you could change, but unfortunately it appears that they cut it from the final release:

5

This is very unfortunate because the number of settings that you can change for C# formatting is, as you can see, extremely limited.

Oh well, i was curious to see whether Agatha’s in-process Hello World example would work so i just started the Sample.ServiceAndClientInSameProcess console project.  Now, keep in mind that this in-process sample doesn’t use Silverlight, nor WCF, nor ASP.NET… it’s just a simple .NET process.  Unfortunately, it crashed:

6

Now, before people blame the Castle.MicroKernel code for this problem it’s important to remember that this code works without problems on Windows with Microsoft’s .NET runtime.   And that is basically the problem i’ve had with Mono every time i tried it for more than something trivial.  Code that works on Microsoft’s .NET runtime should behave exactly the same on Mono if they ever want to be a viable cross-platform .NET implementation.  Hell, even bugs in Microsoft’s .NET runtime should be duplicated, so i don’t care if there’s a bug in either Mono’s or Microsoft’s implementation of the ReaderWriterLock class.  Both implementations should behave the same and that’s all there is to it.

I still wanted to see it working on Mono, so i went to the part of the code that configures Agatha to use Windsor:

7

This isn’t the default color scheme that MonoDevelop uses, but it is one of the default schemes that ships with the IDE which is certainly a nice touch.

I just needed to change the last argument to the ServiceLayerAndClientConfiguration constructor to a new instance of Agatha.Unity.Container and then i could try it again.  Except that i still had to add a reference to the Agatha.Unity project to this console project.  So i opened the Edit References dialog and was very happy to see this:

8

I wasn’t happy because it’s a nice screen (which it isn’t) but because it showed up instantly.  And notice that it lists all of the assemblies that are present in the GAC, which for some reason works instantly on Mono yet takes ages to do in Visual Studio 2008.  I switched over to the Projects tab because i needed to select the Agatha.Unity project as a reference:

9

It’s nice to know that at least some developers can develop a reference-managing screen which enables you to manage your references in a fraction of the time it would take merely to load a similar screen in Visual Studio 2008, without having to resort to the workaround that will be used in Visual Studio 2010.

After that, the Hello World sample still didn’t work properly.  The output of the asynchronously sent request wouldn’t show in the console output but there were no exceptions being thrown either.  So i put a breakpoint in the request handler to make sure that it was at least being executed twice (once for the synchronous request, once for the asynchronous request):

10

I was glad to see the debugger actually break upon entering the breakpoint because that was one of the things that also didn’t work in the beta 1 release of MonoDevelop 2.2.  But anyways, it hit this breakpoint twice so both Hello World requests were indeed handled, yet the response for the asynchronous request didn’t make its way to the console output for some reason.  I added a breakpoint in the AsynchRequestDispatcher class to see if the response at least made its way into that part, and that’s when the debugging experience started to go wrong.  After stepping through a couple of lines of code, it just stopped debugging and ran through the code as if there was no more debugger attached.  I tried this a couple of times, always with the same result, except for 2 situations where the IDE would freeze, and the mono process holding both my CPU cores hostage at 100% usage.  After about 8 attempts, i just gave up.

The MonoDevelop project certainly has made some huge improvements since the last time i tried it (3 months ago), but this should not have been a final release.  Yes, you can finally write code in it.  Yes, you can debug it.  But no, it’s certainly not stable.  Debugging can lead to hard crashes.  Sometimes, the IDE doesn’t close properly and you have to kill the process.  There was one case where i lost syntax highlighting and intellisense in one method while it still worked in other methods.   Restarting MonoDevelop brought back the syntax highlighting and intellisense in that method.  I also ran into some UI glitches where the GTK treeview used in the solution explorer no longer wanted to expand its items.  I had to start clicking on other UI components before i could get the treeview to expand or collapse its items again.  Sometimes, button clicks didn’t seem to be registered immediately and i had to click a couple of times.  And no, it’s not a problem with my mouse since i don’t run into this with any other application.  Though MonoDevelop is the only GTK application that i’ve used on this machine.

But still, if you think about the considerable improvements that the MonoDevelop team has made in the past 3 months, the remaining issues should probably be easy tasks to finish.  Which makes it all the more frustrating that this final release seems to be rushed.  Hopefully, the next release will make it a truly usable IDE for .NET on OS X.

As for the Mono project itself… i find it troubling that i can’t run my code on their latest 2.6.1 release.  This is standard .NET code that runs perfectly fine on Microsoft’s .NET runtime and again, it should run exactly the same on Mono.  And i always seem to run into issues with this whenever i try Mono.  Yet at the same time, many people often claim that Mono is indeed a viable alternative for cross-platform .NET development.  I can’t help but wonder if those people only seem to try very trivial stuff, or if they are actively working around bugs in the Mono libraries.  I really want Mono to succeed, but so far, none of my attempts at running non-trivial .NET code on Mono have gone without problems.   And i’m willing to bet that i’m not the only one, because that certainly would be a very, very big coincidence.

Unit Tests And Silverlight

9 commentsWritten on December 16th, 2009 by
Categories: Silverlight, testing

Capture

This is something that Steven De Kock and Tom Ceulemans (two coworkers of mine without a blog, so no link) have been working on.  Those are Silverlight tests, executing in the Silverlight runtime, within a full browser context.

And yes, they will release it as an open source project soon :)

I Buy Too Many Books

13 commentsWritten on December 15th, 2009 by
Categories: Books

I've developed this bad habit of reading about a book (usually in blog posts), thinking "hmm, that should be interesting", going to Amazon, ordering it and then forgetting all about it. The whole process takes less than 2 minutes. I have recently bought the following books, all of which i still have to finish:

  • 97 Things Every Project Manager Should Know: i love the 97 Things series, and i think it's important to figure out how project managers think (just as it's important for men to figure out how women think) so i had to pick this one up. I am about halfway through at the moment.
  • Debug It!: Too many developers have trouble figuring out where to look when something goes wrong. I'm proud not to be a part of that group (on most days), though i keep my eyes and ears open for any kind of debugging tips so i just had to pick this one up.
  • Growing Object-Oriented Sofware, Guided By Tests: i never knew about this book, but i happened to glance over it in a list of recommended books based on another book that i was buying at the time. Once i spotted the "Kent Beck Signature Book"-series logo i clicked the "Add to shopping cart" button. That's right, i'm that big of a Kent Beck fanboy.
  • Advanced .NET Debugging: This is the book i got suckered into buying today... why? because Tess Ferrandez recommended it. Yup, i'm that easy. Seriously though, how could it be bad?
  • Writing Secure Code: 2nd Edition: I started reading this about 2 months ago. I'm currently at page 154. It's that boring.
  • Enterprise Integration Patterns: As cool as i suspect this book to be, i still haven't made it past the first chapter. Which i started about 3 months ago. It's not that it's boring, i actually think that messaging is very cool... but for some reason i can't get myself to read this thoroughly when there are other things to do that are more relevant to what i need at work.

Don’t Be A Whiny Developer

9 commentsWritten on December 15th, 2009 by
Categories: Opinions, work/career

Ever had to work with a developer who continuously bitches whines about everything? It’s one of the worst possible things that can happen to a team of developers.  I have one golden rule when it comes to bitching: if you are willing to put in the effort to improve the situation, then i don’t have a problem with it.  In fact, i bitch a lot too but at least i try to improve whatever it is that i’m bitching about.  If you’re merely bitching but not willing to put some effort into improving things, then you would really do everyone a favor by simply keeping your mouth shut.

Let’s examine for a second how a whiny developer can come across to his/her coworkers:

  • you might be very lazy because you don’t want to solve problems you’re complaining about
  • you might be incapable of solving problems that you complain about
  • you might just be unwilling to actually solve problems
  • you might just expect other people to solve your problems all the time
  • you might just be completely out of touch with reality
  • you’re probably not a good teammate
  • you probably only care about what you need to do
  • you are definitely a huge pain in the ass

Either one of those isn’t very good, is it? Not to mention when people think more than one those things of you.

I think a team of developers is always better off without the whiny developer.   It’s what professional sports coaches often call “Addition by subtraction”.  Sometimes you have a talented team that isn’t going anywhere.  They aren’t winning the games they should be capable of winning and the team gives the impression that they’ve simply stopped caring.  In many cases, these teams suddenly start performing better once the rotten apple in the group has been traded or simply cut from the team.  No matter how talented you might be, if you aren’t translating that talent into actual value and are just wearing down your team mates, then you don’t belong on the team.

If you’re a developer who complains a lot, please think about what your presence on a team really means.  Are you really contributing anything positive?  Could it be possible that the team is better off without you?  Would you really not care if your team members would rather not work with you?  Can you understand why your team members complain about you?