aboutsummaryrefslogblamecommitdiffstats
path: root/reference/csharp/eina/src/eina_log.cs
blob: 0e8664bd27d1d25052a78c1bbab9fd343d65fe12 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                                
                                                          


                          
                                                                                           

                                                
                                                        

















                                                            
                                                        


                                                                                        
                                                     





                                                                                  
                       





                        
                           

     

/*
 * Efl Core Log examples.
 *
 * This demo shows how to log at various levels and to change what log is shown.
 * You can also use a custom log printer in your app as shown in _log_custom.
 */

using System;

public class Example
{
    static double Divide(int num, int denom)
    {
        if (denom == 0)
            Eina.Log.Critical("Attempt to divide by 0\n");
        else
        {
            if (denom < 0)
                Eina.Log.Warning("Possible undesirable effect, divide by negative number");

            double ret = ((double) num / denom);
            Eina.Log.Info($"{num} / {denom} = {ret}\n");
            return ret;
        }

        return -1;
    }

    static void Divides()
    {
        Divide(5, 1);
        Divide(5, -1);
        Divide(5, 0);
    }

    static void LogLevels()
    {
        Console.WriteLine("Executing with default logging");
        Divides();

        Eina.Log.GlobalLevelSet(Eina.Log.Level.Warning);
        Console.WriteLine("Executing with Warning level"); // same as EINA_LOG_LEVEL = 2
        Divides();

        Eina.Log.GlobalLevelSet(Eina.Log.Level.Info);
        Console.WriteLine("Executing with Info on"); // same as EINA_LOG_LEVEL = 3
        Divides();
    }

    public static void Main()
    {
        Efl.All.Init();

        LogLevels();

        // TODO: missing
        //LogCustom();

        Efl.All.Shutdown();
    }
}