REad content from Log file

Dani_S 3,296 Reputation points
2024-07-03T07:22:47.6+00:00

Hi,

I want to read this value, how is done?

C:\GssdDesktopClient\Logs\GssdDesktopClient.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:\GssdDesktopClient\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,197 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 29,031 Reputation points Microsoft Vendor
    2024-07-04T06:49:52.24+00:00

    Hello,

    It is on Windows platform, and you know the file path, right? If so, please refer to the following code:

    #if WINDOWS
    var stream = await FileSystem.OpenAppPackageFileAsync("a.log");// your log file in Raw folder
    XmlDocument XNLDOC = new XmlDocument();
    XNLDOC.Load(stream);
    XmlNodeList list = XNLDOC.SelectNodes("configuration");
    XmlNode configuration = list[0];
    XmlNodeList listLog4List = configuration.SelectNodes("log4net");
    XmlNode appender = listLog4List[0];
    XmlNode fileNodes = appender.ChildNodes[1];
    XmlNodeList appenderList= fileNodes.SelectNodes("file");
    XmlNode itemNode = appenderList[1];
    string fileValue = itemNode.Attributes["value"].Value;
    Debug.WriteLine(fileValue);
     
    //foreach (XmlNode item in appenderList)
    //{
    //    string value = item.OuterXml;
    //    string nodeValue = item.Attributes["value"].Value;
    //    Debug.WriteLine("{0},--{1}", value,nodeValue);
    //}
    #endif
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful