This repository was archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog4netFixerModule.cs
More file actions
49 lines (44 loc) · 1.36 KB
/
Log4netFixerModule.cs
File metadata and controls
49 lines (44 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Reflection;
using System.IO;
using System.Diagnostics;
namespace Log4netFixer
{
public class Log4netFixerModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
FixNewLog4net();
}
/// <summary>
/// We use a hack to allow our software to use a newer version.
/// http://ponifaax.wordpress.com/2009/01/05/dll-version-conflict-with-log4net/
/// </summary>
public static void FixNewLog4net()
{
AppDomain current = AppDomain.CurrentDomain;
current.AssemblyResolve += new ResolveEventHandler(ForwardLog4NetResolver);
}
// handler is called only when the CLR tries to bind
// to the assembly and fails.
private static Assembly ForwardLog4NetResolver(object sender, ResolveEventArgs args)
{
string assemblyName = args.Name.Substring(0, args.Name.IndexOf(","));
if (assemblyName.StartsWith("log4net"))
{
var thisAssembly = new Uri(typeof(Log4netFixerModule).Assembly.CodeBase).AbsolutePath;
string binFolder = Path.GetDirectoryName(thisAssembly);
string log4netPath = Path.Combine(binFolder, "log4net-1.2.11", "log4net.dll");
return Assembly.LoadFrom(log4netPath);
}
return null;
}
}
}