It took me a while to get to it, but now you can watch the great talk by Roy Osherove on team leadership, from IDCC conference last month:
The quality is not the best, to say the least. I've been using a cheep Canon digicamera, and it's the first time I'm uploading *any* video, so please concentrate on the amazing quality of the content, not on the crappy visual
So you want to be able to do some logging from your code.
log4net for example, is a very common logging framework for .NET, and using it is pretty straight forward, and the net is full of log4net intros.
Usage example:
namespace My.Application
{
public class UsingLog4netDirectly
{
private static log4net.ILog logger = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName);
...
...
...
}
}
However, there are some caveats with using it directly.
Windsor, once again, can help a lot with making it much easier. e.g:
namespace My.Application
{
public class UsingLogIntegration
{
readonly ILogger logger;
public UsingLogIntegration(ILogger logger)
{
this.logger = logger;
}
...
...
...
}
}
Windsor will take care of injecting the correct logger instance, with the name set correctly (using the class name, not needing the wacky MethodBase… stuff)
So, what do you set this up?
Assuming you already use Windsor, you need
You actually do not need to reference these assemblies, only make sure they are on the application’s bin folder. If you use the programmatic configuration (like I do), you’d also need the first (the facility) referenced from your code.
container.AddFacility("LoggingFacility", new LoggingFacility(LoggerImplementation.Log4net));
and … that’s it !
You still need to setup log4net’s configuration, and tell the application where it is:
log4net.Config.XmlConfigurator.Configure();
Easy. Instead of configuring the facility, you simply configure another implementation.
container.Register(Component.For
If you'd explore the Castle.Core.Logging namespace you'd find few, very useful built-in implementations, such as a NullLogger (which you get by calling NullLogger.Instance), ConsoleLogger, StreamLogger (write to a file or memory stream), TraceLogger (writes to the diagnostic trace output) and WebLogger (writes to the HttpContext’s Trace, visible at trace.axd).
For times when one wants the average of a collection of numbers, Linq’s Average() extension method is an easy win.
The problem is that it won’t work on a collection of byte elements.
The initial attempt would be:
var numbers = new byte[] {1, 2, 3, 4};
var avg = numbers.Cast<int>().Average();
Console.WriteLine(avg);
However this will fail with
Unhandled Exception: System.InvalidCastException: Specified cast is not valid. at System.Linq.Enumerable.d__aa`1.MoveNext() at System.Linq.Enumerable.Average(IEnumerable`1 source)
The workaround is to cast using the Select operator, and manually cast to int:
var numbers = new byte[] {1, 2, 3, 4};
var avg = numbers.Select(b=>(int)b).Average();
Console.WriteLine(avg);
The author of the best explanation that will be posted as a comment to this post will get a huge prize (in other words – might get a mention in a follow up post …)
This was a short reminder-post. I do have some more interesting things awaiting in the pipe, and I promise to re-attend my blog now that the pressure of the new baby and of setting up the IDCC conference is out of the way. Good things comes to those who wait blah blah blah.