One solution is to get the latest log4net source code from its subversion repository, compile for .Net 2.0, and you’re in business… but that might cause you other headaches if they unexpectedly changed something else that you were using.

The alternative is to download the source of the latest public release (1.2.10) and patch it yourself as follows:

The fix involves making two small changes to the log4net code, and adding a corresponding value to your log4net configuration.

1) download the source code from the Apache web site
2) unzip it
3) open the sln file (under src) with Visual Studio
4) find the SmtpAppender class (under log4net/Appender)
5) search in that class for “public MailPriority Priority”
6) add the following new property after that it:

public bool EnableSsl { get; set; }

7) search for “smtpClient.Send(mailMessage)”

Notice that this segment of code is grayed-out. That’s because the project has a conditional compilation symbol named NET_1_0 that is enabled by default and this code segment is enclosed in a conditional compilation symbol named NET_2_0. We need to enable this segment of code. To do that:

7a) right click on the log4net project in the solution explorer and select “Properties”
7b) change the conditional compilation symbol version

7c) close the properties tab
7d) the code segment should no longer appear grayed-out
7e) above the “smtpClient.Send” line you searched for add the following:

smtpClient.EnableSsl = EnableSsl;

8 ) when you try to compile you’ll get an error in XmlConfigurator related to System.Configuration.ConfigurationManager. This is because the project does not have a reference to the System.Configuration assembly. Add the reference.

9) you’ll also get an error related to a missing NUnit reference in the test project. You can add one and run the tests – several fail by the way but none are related to the change we made, they were checked in that way. Seriously. Anyway, you could also skip that part and compile only the log4net project.

10) replace the log4net assembly in your project with the one from build\bin\net\1.0\debug

11) update the SmtpAppender segment of your app.config to include the EnableSsl setting