Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 3.0.1 bring new issues #193

Closed
NoahHabanero opened this issue Oct 14, 2024 · 7 comments
Closed

Update to 3.0.1 bring new issues #193

NoahHabanero opened this issue Oct 14, 2024 · 7 comments

Comments

@NoahHabanero
Copy link

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
Copy link
Contributor

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
Copy link
Author

ok I have written to him,

What of the log4net.Util.PatternString issue?

@gdziadkiewicz
Copy link
Contributor

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

FreeAndNil added a commit that referenced this issue Oct 14, 2024
@FreeAndNil
Copy link
Contributor

ok I have written to him,

What of the log4net.Util.PatternString issue?

@NoahHabanero I added a unit test for your problem (see 79b57e5).
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
Copy link
Contributor

gdziadkiewicz commented Oct 15, 2024 via email

@gdziadkiewicz
Copy link
Contributor

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.

@NoahHabanero
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants