examples/reference/csharp/eina/src/eina_log.cs

63 lines
1.4 KiB
C#

/*
* 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();
}
}