Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application stopped logging after using ILMerge

I have a very modest application with a single external assembly (log4net.dll) that I wanted to use ILMerge on. I merge the App.exe and the log4net.dll, and the resulting executable (New.exe) appears to work correctly. However, New.exe is no longer logging and it was logging fine before being merged. Bear I mind I copied App.exe.config over before testing New.exe.

I'm not sure what to make of this. Does anybody have any idea why this would happen? Have I mis-used ILMerge.exe some how? Reflector seems to indicate that New.exe is "whole"; I can see the Log4net assembly and everything.

like image 946
peacedog Avatar asked Dec 28 '22 22:12

peacedog


2 Answers

I do not know the internals of log4net, but I suspect it's looking for the log4net assembly and can't find it since you merged it into new.exe. A solution to this is to provide the AssemblyResolve event in the AppDomain with a function that remaps log4net.dll to new.exe.

like image 67
Joel Lucsy Avatar answered Jan 09 '23 12:01

Joel Lucsy


My immediate guess would be that by changing the assembly name of the log4net assembly, you've somehow broken it's type resolution, probably for the logging configuration.

Bear in mind that your type names are now different.

This means that a type name such as

log4net.Appender.RollingFileAppender, log4net

would now be

log4net.Appender.RollingFileAppender, new

(or somesuch)

Check your logging configuration, fully qualifying any appenders, layout patterns, etc (basically any log4net type names that appear in config) to point to your new assembly.

Additionally, if your logging config is in your web.config or app.config (as opposed to a seperate file), then the section definition will also need amending:

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

would become something like

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, 
    new" />
like image 37
Rob Levine Avatar answered Jan 09 '23 12:01

Rob Levine