Update to 3.0.1 bring new issues
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
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
ok I have written to him,
What of the log4net.Util.PatternString issue?
Hi, I will take a look today. BTW, congrats on releasing version 3 of log4net
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.
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: @.***>
Hi @NoahHabanero ,
I did the move to log4net 3.0.1 in log4net.Ext.Json. There is a pre-release version 3.0.1-develop1504356721 you can test.
The funny thing I found out while testing if it resolves your problems is that the config in the repro is invalid. Instead of
<layout type="log4net.Layout.PatternLayout, log4net.Ext.Json"> you probably meant <layout type="log4net.Layout.SerializedLayout , log4net.Ext.Json"> . Can you check if new version and the config change resolve your problem?
On my side the error with the config change and old log4net.Ext.Json version is:
log4net:ERROR XmlHierarchyConfigurator: Failed to construct object of type [log4net.Layout.SerializedLayout] Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeLoadException: Derived method 'Convert' in type 'log4net.Layout.Pattern.JsonPatternConverter' from assembly 'log4net.Ext.Json, Version=2.0.10.1, Culture=neutral, PublicKeyToken=null' cannot reduce access.
at log4net.Layout.SerializedLayout.ActivateOptions()
at log4net.Layout.PatternLayout..ctor(String pattern)
at log4net.Layout.SerializedLayout..ctor()
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
--- End of inner exception stack trace ---
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetType, Type typeConstraint)
log4net:ERROR Failed to create object to set param: layout
logs should be logging.
Check the log file in the Logs folder.
which corresponds nicely to the code change (adjusting access modifier) I did during the move from 2 to 3.
Hi @gdziadkiewicz ,
I have updated to version log4net 3.0.2
And to your log4net.Ext.Json pre-release 3.0.1-develop1517163871
As Well as changed from log4net.Layout.PatternLayout --> log4net.Layout.SerializedLayout
The test project is working as expected! @gdziadkiewicz once version 3.0.1 is released as a stable version. I will update my main project. Thank you all for your work and support!
@FreeAndNil thank you for the configuration advice, you are correct, it is working.