Exemplo n.º 1
0
        static void Log_usage_example()
        {
            try
            {
                Log.Initialize(Log.Mode.EACH_SESSION_IS_IN_OWN_FORLDER);

                Log.Inform("test");
                ThreadRoutines.StartTry(() =>
                {
                    Log.Inform0("to default log");
                    Log.Thread.Inform0("to thread log");
                    throw new Exception2("test exception2");
                },
                                        (Exception e) =>
                {
                    Log.Thread.Error(e);
                }
                                        );

                Log.Session s1 = Log.Session.Get("Name1"); //open if not open session "Name1"
                Log.Writer  nl = s1["Name"];               //open if not open log "Name"
                nl.Error("to log 'Name'");
                s1.Trace("to the main log of session 'Name1'");
                s1.Thread.Inform("to the thread log of session 'Name1'");
                s1.Rename("Name2");
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemplo n.º 2
0
        public static void Run()
        {
            //default configuration: everything is written to the same file in the same folder:
            Log.Inform("write out of box");
            Log.Thread.Inform("write out of box2");
            Log.Head["test"].Inform("write out of box3");
            Log.Session.Get("GAME")["client"].Inform("write out of box4");
            Log.Session.Get("GAME").Rename("Game");

            //a session-less log which will be continued with the next launch of the application
            Log.Get("history").Inform("session-less log");

            //optional initialization. You will like to perform it at the very beginning of the app.
            Log.Initialize(Log.Mode.FOLDER_PER_SESSION);

            //trivial usage: everything is written to the same file
            Log.Inform("write to the default log of the default session");
            Log.Inform("Root log folder: " + Log.RootDir);

            //more sophisticated usage
            Log.Head["Action1"].Inform0("write to log 'Action1' of the default session");

            //writing thread logs to the default session
            ThreadRoutines.Start(task);
            ThreadRoutines.Start(task);

            //writing to an explicitly created session
            Log.Session logSession_Task = Log.Session.Get("TASK");    //create if not exists
            logSession_Task.Inform("write to the default log of the session '" + logSession_Task.Name + "'");
            Log.Writer log_Task_Subtask = logSession_Task["Subtask"]; //create if not exists
            log_Task_Subtask.Error("write to log '" + log_Task_Subtask.Name + "' of session '" + logSession_Task.Name + "''");
            logSession_Task.Trace("write to the default log of the session '" + logSession_Task.Name + "'");
            logSession_Task.Thread.Inform("write to the thread log " + Log.Thread.Id + " of the session '" + logSession_Task.Name + "'");
            //sometimes you may need to rename a log session:
            logSession_Task.Rename("renamed_TASK");
            //optional; close the handlers and free memory
            logSession_Task.Close(false);

            //writing thread logs to explicitly created sessions
            Task.Start("TASK1");
            Task.Start("TASK2");
        }
Exemplo n.º 3
0
        public static void Run()
        {
            //default configuration: everything is written to the same file in the same folder:
            Log.Inform("write out of box");
            Log.Thread.Inform("write out of box2");
            Log.Head["test"].Inform("write out of box3");
            Log.Session.Get("GAME")["client"].Inform("write out of box4");
            Log.Session.Get("GAME").Rename("Game");


            //optional; initialize log
            Log.Initialize(Log.Mode.FOLDER_PER_SESSION);//if permissions allow it, log will be created in the executable directory

            //trivial usage: everything is written to the same file
            Log.Inform("write to the default log of the default session");

            //more sophisticated usage is below
            Log.Head["Action1"].Inform0("write to log 'Action1' of the default session");

            //writing thread logs to the default session
            ThreadRoutines.Start(task);
            ThreadRoutines.Start(task);

            //writing to an explicitly created session
            Log.Session logSession_Task = Log.Session.Get("TASK");    //create if not exists
            logSession_Task.Inform("write to the default log of the session '" + logSession_Task.Name + "'");
            Log.Writer log_Task_Subtask = logSession_Task["Subtask"]; //create if not exists
            log_Task_Subtask.Error("write to log '" + log_Task_Subtask.Name + "' of session '" + logSession_Task.Name + "''");
            logSession_Task.Trace("write to the default log of the session '" + logSession_Task.Name + "'");
            logSession_Task.Thread.Inform("write to the thread log " + Log.Thread.Id + " of the session '" + logSession_Task.Name + "'");
            //sometimes you may need to rename a log session:
            logSession_Task.Rename("renamed_TASK");
            //optional; close the handlers and free memory
            logSession_Task.Close(false);

            //writing thread logs to explicitly created sessions
            Task.Start("TASK1");
            Task.Start("TASK2");
        }