Skip to content

Files

Latest commit

01f89bc · Jul 9, 2023

History

History
114 lines (109 loc) · 2.9 KB

SimpleLogging.md

File metadata and controls

114 lines (109 loc) · 2.9 KB

Learning simple logging

NOTE: this tutorial assumes you've already gone through the Getting Started section. If you haven't, this tutorial might not work for you.

Logging to the console

This is super basic, and super simple. First of all, set your LogLevel like you were taught in the last tutorial:

namespace ExampleProject
{
    class ExampleProject
    {
        static void Main(string[] args)
        {
            Logger logger = new Logger();
            logger.SetLevel(Logger.LogLevel.Note); // This is just an example, you can pick any one of the five
        }
    }
}

Next, log your message to the console using the Log(string) function. As you can see, your data should be in the string type. Overloads with other types haven't been added yet.

namespace ExampleProject
{
    class ExampleProject
    {
        static void Main(string[] args)
        {
            Logger logger = new Logger();
            logger.SetLevel(Logger.LogLevel.Note);
            logger.Log("This is some data I'm logging to the console"); // Replace with whatever data you need
        }
    }
}

And when running your project, you'll find this in the console: [NOTE]: This is some data I'm logging to the console. Yours will vary in colour and type depending on the LogLevel you picked in the SetLevel() function.

Examples

Note

namespace ExampleProject
{
    class ExampleProject
    {
        static void Main(string[] args)
        {
            Logger logger = new Logger();
            logger.SetLevel(Logger.LogLevel.Note);
            logger.Log("This is some data I'm logging to the console.");
        }
    }
}

Info

namespace ExampleProject
{
    class ExampleProject
    {
        static void Main(string[] args)
        {
            Logger logger = new Logger();
            logger.SetLevel(Logger.LogLevel.Info);
            logger.Log("This is some data I'm logging to the console.");
        }
    }
}

Warning

namespace ExampleProject
{
    class ExampleProject
    {
        static void Main(string[] args)
        {
            Logger logger = new Logger();
            logger.SetLevel(Logger.LogLevel.Warning);
            logger.Log("This is some data I'm logging to the console.");
        }
    }
}

Error

namespace ExampleProject
{
    class ExampleProject
    {
        static void Main(string[] args)
        {
            Logger logger = new Logger();
            logger.SetLevel(Logger.LogLevel.Error);
            logger.Log("This is some data I'm logging to the console.");
        }
    }
}

Fatal

namespace ExampleProject
{
    class ExampleProject
    {
        static void Main(string[] args)
        {
            Logger logger = new Logger();
            logger.SetLevel(Logger.LogLevel.Fatal);
            logger.Log("This is some data I'm logging to the console.");
        }
    }
}