-
-
Notifications
You must be signed in to change notification settings - Fork 333
log4net logs PlatformNotSupportedException on Android #239
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
Comments
@FreeAndNil any suggestions? |
@arunjose696 can you post your config file? |
Do I even need a config file in BasicConfigurator.Configure()?;, I was using BasicConfigurator.Configure() to make the reproducer minimal so for this case I did not use a config file. I also tried using the below example with XmlConfigurator.Configure
|
This is a valid log4net configuration, but not a valid app.config. |
I am using MAUI with dotnet 9, there is no app.config file, From what I understand from here app.config is a older style https://learn.microsoft.com/en-us/answers/questions/1510926/why-do-some-c-applications-have-an-app-config-file Do you have any documentation on how to do the cofiguration for MAUI apps? |
You just add a config file via "Add ..." and paste the content from #153 (comment) |
I tried adding the app.config file still I see the Exception |
Can you zip your test project and post it here? |
Here is the zip file, There are just very minor changes from the basic MAUI app created in visual studio. |
Your app runs fine on my PC (Win11 24H2 / VS 17.13.6).
Please take a look at the adjusted sample: |
Thank you for the response. I also tried using this zip file. The code runs perfectly fine when executed on the Windows machine in Visual Studio, but the exception only occurs when I try running it on an Android device or emulator. I change the run configuration in Visual Studio from the Windows machine to the Android emulator. Could you please try running it on an Android emulator in Visual Studio? Apologies for not mentioning earlier that I am running on Android. |
You need to use xml (config) files for android. See the attached example. More details for log4net config files can be found here |
Do you have the logs being written with this project? Because in my end it is just the same exception as before in the Debug logs. I see the complaint that the config file is not well formed even when using the same project without any changes. Could you share the path of the log file created? Also are there no exceptions like below in the debug logs in visual studio?
|
I have no android device for testing. The message above is "just" a warning. I will fix this, when your main problem is solved. |
I see maui.log is the value , I dont see this file being created in the Android device or the emulator. |
Can you fully qualify the file name in the xml file? |
As directly giving the fully quallified path in xml wont work in maui, I think I will need to provide this somehow through the code which I need to figure out, If I dont give the filename too shouldnt it log to the console? I donmt see the logs being logged to console as well. |
You can read the log4net config from an embedded resource: MauiApp5.zip This way (and changing the file name to fully qualified) works for me: |
Thanks very much. Making the app as embedded resource works for me. The fully quallified name though works on the android emulator did not work on the real android device. However just using maui.log as the filename writes the log to this path /data/data/com.companyname.mauiapp3/files/maui.log. Which means the logging defenitely works without issues. Still in the debug logs we have the warning/traceback which says |
Thanks for the confirmation. |
@arunjose696 see #240 |
#239 detect Android and use environment variables instead of AppSettings
Thanks the traceback is gone now, checked with prerelease. |
I'm experiencing the same problem described in issue #153 . I've put together a minimal example using a basic .NET MAUI app to reproduce it.
In this simple MAUI app, log4net doesn't seem to work. All I did was create a new .NET MAUI project in Visual Studio and install log4net via the NuGet package manager. Then, inside MauiProgram.CreateMauiApp(), I attempted to use log4net for logging. Even when I use BasicConfigurator—which, according to https://logging.apache.org/log4net/release/manual/configuration.html shouldn't require any XML configuration, it still fails.
Find below my code and exception
In the debug logs I see this exception .
It also fails when I use XmlConfigurator.Configure() and provide that the config file must be copied as is to the target directory (and using the default build action for config files) as mentioned in #153 (comment)
I use maui -> 9.0.4
log4net-> 3.0.4
.net -> 9
The text was updated successfully, but these errors were encountered: