Using LogLevel example

Hi, i use .Net Sdk , and need more log info. Where i can find examples of SDK setting loglevel and use it.

thanks
best regards

It can be configured under the Sync App Class like so -

    public partial class App : Application
    {
        private const string appId = "YOUR REALM APP ID";
        public static Realms.Sync.App RealmApp;
        public static Realms.Sync.AppConfiguration appConfiguration;


        public App()
        {
            InitializeComponent();
        }

        protected override void OnStart()
        {
            appConfiguration = new AppConfiguration(appId)
            {
                LogLevel = LogLevel.All,
                CustomLogger = ((str, level) => {
                    Console.Write(str);
                })
            };

Hi,
AppConfiguration.LogLevel is marked as obsolete, with message “Configure the Global RealmConfiguration.LogLevel instead”.

CustomLogger is deprecated.

Thanks

The deprecation message is misleading and we’ve corrected it, but haven’t released the fix yet. You can use the Logger class:

using Realms.Logging;

...

Logger.LogLevel = LogLevel.All;
// If you want to customize the logging function:
Logger.Default = Logger.Function(message =>
{
    // Do something with the message
});
1 Like

I am not getting any log messages in the console. Do you have a sample Xamarin.Forms project example?

Logger.Console.Log(LogLevel.All, “Hello”);

Do you see Console.WriteLine messages - e.g. if you replace that code with Console.WriteLine("Hello"), do you see the message appear?

I am getting Hello to print on the Android project but not the Windows project (Xamarin.Forms). That’s Okay, but we are trying to find a Log Entry for a “Realms.Exceptions.RealmException: null” in a try catch block.

I’m sorry, but I don’t understand what the problem is and how it’s related to Logger.Console. It uses Console.WriteLine under the hood for Xamarin projects, so it should behave fairly similarly. Your issue doesn’t appear to be related to the original question, so it’s probably better to create a new post providing more information about what doesn’t behave as expected, or - if you believe this is a bug - file a new bug report with the .NET repo: Sign in to GitHub · GitHub.

I am trying to view the trace logs. Are the logs displayed in the Realm server side logs or in the output console?

They are output in the console - they are not sent to the server.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.