Darren Ferguson - Blog
10 August 2010 at 09:00
Log4net for Umbraco package developers
Note: This information is also posted on the Umbraco Wiki
See also: ismailmayat.wordpress.com/.../
- Download log4net
- In your visual studio project add a reference to log4net.dll (use bin\net\2.0\release in the distribution)
- Open AssemblyInfo.cs in the properties folder of your solution.
- Add the following attributes:
[assembly: XmlConfigurator(ConfigFile = @"config\my.log4net.config", Watch = true)]
[assembly: RepositoryAttribute("MyAppName")]Note: RespositoryAttribute is used to identify a distinct configuration for your unique package/assembly it can be any value you wish but try to avoid conflicts.
By specifiying watch=true in the XmlConfigurator attribute you can modify the logging config during development and it will be automatically reloaded without causing an application restart.
A simple configuration file could be as follows:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="R" type="log4net.Appender.RollingFileAppender">
<file value="${TEMP}/myPackage.log" />
<appendToFile value="true" />
<maximumFileSize value="1000KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %thread %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="R" />
</root>
</log4net>The above logs to a file in your system tmp directory - The file is rotated once it reaches 1 MB and the last two versions are maintained. Log4net can log to XML files, databases, email etc and you can define different loggers for different classes and different log targets for different levels of logging. See log4net Manual - Configuration for more details.
In your package classes add a logger declaration, for example:
using System;
using umbraco.BusinessLogic;
using log4net;
using System.Reflection;
namespace Umb.Log4Net
{
public class Class1 : ApplicationBase
{
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public Class1()
{
log.Debug("application starting up");
}
}
}Note: When releasing Umbraco packages you may want to set your logging levels to NONE or FATAL to stop DEBUG information being logged.
02 August 2010 at 00:00
Umbraco Workflow foundation project: short update
I recently blogged a screencast which demonstrated integration of Microsoft Workflow foundation into Umbraco. Happily, response was positive and I've had a few questions about when it will be available as a package.
To set expectations, the short answer is that it won't.
The implementation I put together works well for a client of mine as well as my own site, but the effort involved in documenting and polishing it so that it could be released as a package isn't insignificant.
On top of that my prototype is based on workflow foundation 3 and MS have now released version 4. There is no backward compatibility and the new version is for .net 4. When you start to throw past present and future versions of Umbraco into the equation you start to come up with silly exponential sums when working out how many versions would need to be maintained.
So, no package I'm afraid.
However: If you'd like to implement workflow in Umbraco and would like to sponsor the project it could happen. Feel free to get in touch and we can talk it through.