apache / logging-log4net

Apache Log4net is a versatile, feature-rich, efficient logging API and backend for .NET
https://logging.apache.org/log4net
Apache License 2.0
856 stars 326 forks source link

Update to 3.0.1 bring new issues #193

Open NoahHabanero opened 3 days ago

NoahHabanero commented 3 days ago

It looks like there is a a bad interaction between log4net 3.0.1 and log4net.Ext.Json 2.0.10.1 With error:

log4net:ERROR Failed to find type [log4net.Layout.PatternLayout, log4net.Ext.Json]
System.TypeLoadException: Could not load type 'log4net.Layout.PatternLayout' from assembly 'log4net.Ext.Json, Version=2.0.10.1, Culture=neutral, PublicKeyToken=null'.
   at System.Reflection.RuntimeAssembly.GetTypeCore(String typeName, ReadOnlySpan`1 nestedTypeNames, Boolean throwOnError, Boolean ignoreCase)
   at System.Reflection.TypeNameParser.GetType(String typeName, ReadOnlySpan`1 nestedTypeNames, String assemblyNameIfAny)
   at System.Reflection.TypeNameParser.Parse()
   at System.Reflection.TypeNameParser.GetType(String typeName, Func`2 assemblyResolver, Func`4 typeResolver, Assembly requestingAssembly, Boolean throwOnError, Boolean ignoreCase, Boolean extensibleParser)
   at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetType, Type typeConstraint)

Additionally, the issue with log4net.Util.PatternString using global properties to set dynamic log names, For example: <file type="log4net.Util.PatternString" value="C:\Development\TestProjects\Log4NetExample\Logs\DDLogs\dd-%property{LogName}.json" />

This is still not resolved with updates in 3.0.1, in this case, the log name is dd-null where global property "LogName" is set in the main project like so: log4net.GlobalContext.Properties["LogName"] = "custom_log_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");

Reference to duplicate issue:

183, but now in version 3.0.1.

Please find a simple project implementation attached. Log4NetExample.zip

FreeAndNil commented 3 days ago

Hi @NoahHabanero,

can you contact https://gitlab.com/gdziadkiewicz ? It looks like log4net.Ext.Json needs to be adjusted for log4net 3.x

E.g. there are no more matching target frameworks: log4net supports net462 & netstandard2.0 log4net.Ext.Json supports net452, net40, net35, net20, netstandard1.3

NoahHabanero commented 3 days ago

ok I have written to him,

What of the log4net.Util.PatternString issue?

gdziadkiewicz commented 3 days ago

Hi, I will take a look today. BTW, congrats on releasing version 3 of log4net

FreeAndNil commented 3 days ago

ok I have written to him,

What of the log4net.Util.PatternString issue?

@NoahHabanero I added a unit test for your problem (see https://github.com/apache/logging-log4net/commit/79b57e5eff0fb970a8d51ca35b5bf63e0b90a6df). But I can't reproduce. Maybe you set GlobalContext.Properties too late? It must be called before XmlConfigurator.Configure().

If the problem still persists, please create a separate issue.

gdziadkiewicz commented 2 days ago

Hi all, I reproduced the issue and will be working on getting it fixed.

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: Jan Friedrich @.> Sent: Monday, October 14, 2024 5:56:33 PM To: apache/logging-log4net @.> Cc: Grzegorz Dziadkiewicz @.>; Comment @.> Subject: Re: [apache/logging-log4net] Update to 3.0.1 bring new issues (Issue #193)

ok I have written to him,

What of the log4net.Util.PatternString issue?

@NoahHabanerohttps://github.com/NoahHabanero I added a unit test for your problem (see 79b57e5https://github.com/apache/logging-log4net/commit/79b57e5eff0fb970a8d51ca35b5bf63e0b90a6df). But I can't reproduce. Maybe you set GlobalContext.Properties too late? It must be called before XmlConfigurator.Configure().

If the problem still persists, please create a separate issue.

— Reply to this email directly, view it on GitHubhttps://github.com/apache/logging-log4net/issues/193#issuecomment-2411660944, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACBG4D2QK64KN4RDRSEXSLTZ3PSTDAVCNFSM6AAAAABP43DQK6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJRGY3DAOJUGQ. You are receiving this because you commented.Message ID: @.***>