Skip to content

log4net logs PlatformNotSupportedException on Android #239

@arunjose696

Description

@arunjose696

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

using Microsoft.Extensions.Logging;
using log4net;
using log4net.Config;
namespace MauiApp3
{
    public static class MauiProgram
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(MauiProgram));
        public static MauiApp CreateMauiApp()
        {

            BasicConfigurator.Configure();
            log.Info("Entering application.");
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                });

#if DEBUG
    		builder.Logging.AddDebug();
#endif

            return builder.Build();
        }
    }
}

In the debug logs I see this exception .

[DOTNET] log4net:ERROR Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
[0:] log4net:ERROR Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
[DOTNET] System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
[DOTNET]  ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
[DOTNET]    at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
[DOTNET]    at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
[DOTNET]    at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
[DOTNET]    at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
[DOTNET]    at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp()
[DOTNET]    at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp()
[DOTNET]    at System.Configuration.ClientConfigurationSystem..ctor()
[DOTNET]    at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
[DOTNET]    --- End of inner exception stack trace ---
[DOTNET]    at System.Configuration.ConfigurationManager.PrepareConfigSystem()
[DOTNET]    at System.Configuration.ConfigurationManager.GetSection(String sectionName)
[DOTNET]    at System.Configuration.ConfigurationManager.get_AppSettings()
[DOTNET]    at log4net.Util.SystemInfo.GetAppSetting(String key) in D:\Git\apache\logging-log4net\src\log4net\Util\SystemInfo.cs:line 651
[0:] System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
   at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
   at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
   at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
   at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp()
   at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp()
   at System.Configuration.ClientConfigurationSystem..ctor()
   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at log4net.Util.SystemInfo.GetAppSetting(String key) in D:\Git\apache\logging-log4net\src\log4net\Util\SystemInfo.cs:line 651
[DOTNET] log4net:ERROR Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
[0:] log4net:ERROR Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
[DOTNET] System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
[DOTNET]  ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at log4net.Util.SystemInfo.GetAppSetting(String key) in D:\Git\apache\logging-log4net\src\log4net\Util\SystemInfo.cs:line 651
[DOTNET]    at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
[DOTNET]    at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
[DOTNET]    at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
[DOTNET]    at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
[DOTNET]    at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp()
[DOTNET]    at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp()
[DOTNET]    at System.Configuration.ClientConfigurationSystem..ctor()
[DOTNET]    at System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
[DOTNET]    --- End of inner exception stack trace ---
[DOTNET]    at System.Configuration.ConfigurationManager.PrepareConfigSystem()
[DOTNET]    at System.Configuration.ConfigurationManager.GetSection(String sectionName)
[DOTNET]    at System.Configuration.ConfigurationManager.get_AppSettings()
[DOTNET]    at log4net.Util.SystemInfo.GetAppSetting(String key) in D:\Git\apache\logging-log4net\src\log4net\Util\SystemInfo.cs:line 651

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions