Dirty log for font

Dani_S 3,786 Reputation points
2024-07-02T09:25:28.8333333+00:00

Hi,

I get error for in the log, bu app work as expected.

Where this error come from?

Thanks,

2024-06-30 13:47:22,492 [1] ERROR Microsoft.Maui.FontManager - Error loading font 'Assets/Fonts/Arial.ttf'.
System.ArgumentException: The parameter is incorrect.
Assets/Fonts/Arial.ttf is not a valid absolute URI.
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.System.WinRTUriRuntimeClassFactory.CreateUri(String uri)
   at ABI.System.Uri.CreateMarshaler(Uri value)
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet._ICanvasFontSetFactory.Create(Uri uri)
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet.<>c__DisplayClass11_0.<.ctor>b__0()
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet..ctor(Uri uri)
   at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)
2024-06-30 13:47:22,601 [1] ERROR Microsoft.Maui.FontManager - Error loading font 'Assets/Fonts/Arial.otf'.
System.ArgumentException: The parameter is incorrect.
Assets/Fonts/Arial.otf is not a valid absolute URI.
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.System.WinRTUriRuntimeClassFactory.CreateUri(String uri)
   at ABI.System.Uri.CreateMarshaler(Uri value)
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet._ICanvasFontSetFactory.Create(Uri uri)
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet.<>c__DisplayClass11_0.<.ctor>b__0()
   at Microsoft.Graphics.Canvas.Text.CanvasFontSet..ctor(Uri uri)
   at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)

PackageReference

<ItemGroup>


<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />

<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" /><PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />


<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.0.1" />

<PackageReference Include="PInvoke.User32" Version="0.7.104" />

<PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.0" />


</ItemGroup>

I used this code:

       .Services.AddLogging(async configure =>

       {

           var pathToConfig = @"log4net.config";

           await using var stream = await FileSystem.OpenAppPackageFileAsync(pathToConfig);

           var assembly = Assembly.GetAssembly(typeof(MauiProgram));

           var logManager = new AppLogManager(pathToConfig, assembly, stream);

           configure.AddLog4Net(new Log4NetProviderOptions

           {

               ExternalConfigurationSetup = true

           });

       });
 /// </summary>

  public class AppLogManager

  {

  private static AppLogManager _logManager = null;

  public ILog _logger;


 

  private AppLogManager()

  {

  }

  /// <summary>

  /// To encript data or not

  /// </summary>

  public static bool IsEncripted { get; set; } = true;

  /// <summary>

  /// Configure the log4net

  /// </summary>

  /// <param name="fullConfigFilePath">Full config path file</param>

  /// <param name="assembly">The assembly to run under</param>

  /// <param name="stream">The stream relavant for MAUI</param>

  public AppLogManager(string fullConfigFilePath, Assembly assembly, Stream stream = null)

  {

      // log4net.GlobalContext.Properties["LogFileName"] = "C:\\AutomationManager\\Logs\\Client1.log";

      log4net.Config.XmlConfigurator.Configure(stream);

      _logManager = new AppLogManager();



  }

  /// <summary>

  /// Get app loger manager for given  T 

  /// </summary>

  /// <typeparam name="T">The T</typeparam>

  /// <returns>Returns app logger manager</returns>

  public static AppLogManager GetLogger<T>()

  {

      return _logManager.GetLogger(typeof(T));

  }

  /// <summary>

  /// Get app loger manager for given  Type

  /// </summary>

  /// <typeparam name="type">The given type</typeparam>

  /// <returns>Returns app logger manager</returns>

  public AppLogManager GetLogger(Type type)

  {

      _logger = log4net.LogManager.GetLogger(type);

      return _logManager;

  }

  /// <summary>

  /// Write info message to  log

  /// </summary>

  /// <param name="message">The message to log</param>

  public void Info(string message)

  {

      if (IsEncripted)

      {

          message = "GSSD" + AesHelper.Encrypt(message);

      }

      _logger.Info(message);

  }

  /// <summary>

  /// Write error message to log

  /// </summary>

  /// <param name="message">The message to log</param>

  /// <param name="ex">The exception to log</param>

  public void Error(string message, Exception ex)

  {

      if (IsEncripted)

      {

          message = "GSSD" + AesHelper.Encrypt(message);

      }

      _logger.Error(message, ex);

  }

  /// <summary>

  /// Write error message to log

  /// </summary>

  /// <param name="message">The message to log</param>

  public void Error(string message)

  {

      if (IsEncripted)

      {

          message = "GSSD" + AesHelper.Encrypt(message);

      }

      _logger.Error(message);

  }

  /// <summary>

  /// Write debug message to log

  /// </summary>

  /// <param name="message">The message to log</param>

  public void Debug(string message)

  {

      if (IsEncripted)

      {

          message = "GSSD" + AesHelper.Encrypt(message);

      }

      _logger.Debug(message);

  }

  /// <summary>

  /// Write fatal error message to log

  /// </summary>

  /// <param name="message">The message to log</param>

  public void Fatal(string message)

  {

      if (IsEncripted)

      {

          message = "GSSD" + AesHelper.Encrypt(message);

      }

      _logger.Fatal(message);

  }

  /// <summary>

  /// Write fatal error message to log with exception

  /// </summary>

  /// <param name="message">The message to log</param>

  /// <param name="ex">The exception to log</param>

  public void Fatal(string message, Exception ex)

  {

      if (IsEncripted)

      {

          message = "GSSD" + AesHelper.Encrypt(message);

      }

      _logger.Fatal(message, ex);

  }

  /// <summary>

  /// Write warn error message to log

  /// </summary>

  /// <param name="message">The message to log</param>

  public void Warn(string message)

  {

       if (IsEncripted)

      {

          message = "GSSD" + AesHelper.Encrypt(message);

      }

      _logger.Warn(message);

  }
  }

my log:


<?xml version="1.0" encoding="utf-8" ?>

<configuration>


<configSections>

	<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>

</configSections>

<log4net>



<appender name="console" type="log4net.Appender.ConsoleAppender">

	<layout type="log4net.Layout.PatternLayout">

		<conversionPattern value="%date %level %logger - %message%newline" />

	</layout>

</appender>

<appender name="file" type="log4net.Appender.RollingFileAppender">

		<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

	<file type="log4net.Util.PatternString" value="%property{LogFileName}.txt" />

	<file value="C:\ProgramData\Sasa-Software\DesktopClient\Logs\GssdDesktopClient.log" />

	<appendToFile value="true" />

	<rollingStyle value="Size" />

	<maxSizeRollBackups value="5" />

	<maximumFileSize value="25MB" />

	<staticLogFileName value="true" />

	<layout type="log4net.Layout.PatternLayout">

		<conversionPattern value="%date [%thread] %level %logger - %message%newline" />

	</layout>

	<filter type="log4net.Filter.LoggerMatchFilter">

		<loggerToMatch value="Microsoft.Maui.Controls.Xaml.Diagnostics.BindingDiagnostics" />

		<acceptOnMatch value="false" />

	</filter>

</appender>

	<root>

		<level value="INFO" />


	

		<!--<appender-ref ref="console" />-->

		<appender-ref ref="file" />

	</root>
</log4net>

</configuration>
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,579 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.