コード例 #1
0
        /// <summary>
        /// Example of watching a variable in another scope
        /// </summary>
        private static void CheckTheWeather()
        {
            var sky = "Blood moon night";

            HL.Watch(new { sky });
        }
コード例 #2
0
        public static void Run()
        {
            // HypnoLog C# Advanced usage examples:

            // == error handling ==
            // Note: this is an experimental feature

            // You can subscribe to HypnoLog errors to provide your own way of handling such situations
            // Note: it is best to provide an Error handling function before initializing HypnoLog,
            // this will enable you to catch initialization errors as well.
            // TODO: allow passing error-handling-function in initialization method as argument.
            HL.ErrorOccurred += (obj, exception) =>
            {
                Console.WriteLine("Couldn't log using HypnoLog.\nObject: {0}\nError: {1}", obj, exception);
            };

            // == Initializing ==
            // Note: this is an experimental feature

            // Initialize the HypnoLog
            // It is not mandatory to call Initialize but it is recommended to do so as soon as
            // possible in the begging of the program. This will help marking the begging
            // of new session in a proper way, by logging "new session" message.
            // If Initialize was not invoked manually, it will be called implicitly at the first
            // logging action.
            HL.Initialize(
                host: "localhost",
                port: 7000,
                shouldRedirect: false);
            // Also you can call initialization without parameters. Default server will be used (http://localhost:7000/).
            // Setting `shouldRedirect` as `true` equivalent of calling `RedirectConsoleOutput()`, see following.

            // == Redirecting Console output ==
            // Note: this is an experimental feature

            // Calling `RedirectConsoleOutput()` will redirect all `System.Console` output to HypnoLog.
            // This can be useful if u already have a program with a lot of output to the console.
            //HL.RedirectConsoleOutput();

            // == Logging ==
            // Note: this is an experimental feature

            // Example of logging a string with arguments which will be format,
            // as you would do in `Console.WriteLine("x = {0}", x);`
            HL.Log("This is logged form C# version {0} at {1}", Environment.Version, DateTime.Now);

            // TODO: when logging `HL.Log("bal is {0} ", args: "sunny");` the `args` is required
            // otherwise the method is ambiguous
            //HL.Log("bal is {0} ", "sunny");


            // == Tags ==
            // Note: this is an experimental feature

            // Example of logging with tags.
            // To log with tags, add your tags with the `Tag()` method and then invoke the logging method of your choice.
            // You can tag with multiple tags,
            // tags can be separated by hash (`#`) or space(` `).
            HL.Tag("#info").Log("Some data Tagged as info");
            HL.Tag("#info #weather").Log("Weather will be sunny. Tagged as #info and as #weather");
            var detailedWeatherDescription =
                "Weather report received over network:\n" +
                "Weather will be cool and cloudy\n" +
                "Sun will be soft but warm\n" +
                "Waves will be head hight \\m/\n";

            // Combine tagging and named-logging
            HL.Tag("info weather detailed").NamedLog(new { detailedWeatherDescription });
            // Log some graph and tag it
            HL.Tag("#info #numbers").Log(new[] { 1, 2, 3, 4, 5 }, type: "plot");

            // == Named logging ==
            // Note: this is an experimental feature

            // Example of logging variable with its name
            //  This is good to avoid code like this:
            //      var x = GetSomeValue();
            //      Log("x: " + x);
            //  Then you change the name of 'x' to 'y' and the logging become misleading.
            // Note: To log variable with it's name use the "NamedLog" function, and warp the
            // variable with `new {}` deceleration.
            HL.Log("Example of logging with variable name:");
            var walter = "Also known as Mr.White";

            HL.NamedLog(new { walter });

            // == Synchronous usage ==
            // Note: this is an experimental feature

            // In case you want to use some logging methods from scopes do not allow multi-threading
            // such as invoking method from Visual Studio Immediate Window,
            // use the Synchronous version of the logging methods.

            // Example of synchronous logging
            HL.LogSync("Logging some string, synchronously!");

            // == Watching ==
            // Note: this is an experimental feature
            // Not working right now

            //// Example of watching a variable.
            //// Note: To watch variable we need it's name and therefor we have to warp
            //// the variable with new {} deceleration as we do in "NamedLog" function.
            //var sky = "Blue clear sky";
            //HL.Watch(new { sky });
            //// Change the value and watch it changing.
            //sky = "Gray foggy sky";
            //HL.Watch(new { sky });
            //// Example of watching two variables with the same name, in different scopes.
            //CheckTheWeather();
        }
コード例 #3
0
        public static void Run()
        {
            // Log a string
            string str = "Hello HypnoLog from C#!";

            HL.Log(str);

            // Log array of numbers as single line graph ("plot")
            Random randNum = new Random();

            int[] exampleArray = Enumerable.Range(0, 50).Select(i => (i * 10) % 100 + (int)Math.Floor(randNum.NextDouble() * 10)).ToArray();
            HL.Log("Example of logging array of numbers as single line graph (plot):");
            HL.Log(exampleArray, "plot");

            // TODO: log multi line graph

            // Log 2d array as Heatmap
            int[,] arr2d = new int[10, 10];
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    //arr2d[i,j] = randNum.Next(1, 50);
                    arr2d[i, j] = i * 10 + j;
                }
            }
            HL.Log("Example of logging 2d number array as Heatmap:");
            HL.Log(arr2d, "heatmap");

            // TODO: log histogram

            // log Lat-Long Geo locations using Google maps
            var locations = new object[]
            {
                new object[] { "Lat", "Long", "Name" },
                new object[] { 37.4232, -122.0853, "Work" },
                new object[] { 37.4289, -122.1697, "University" },
                new object[] { 37.6153, -122.3900, "Airport" },
                new object[] { 37.4422, -122.1731, "Shopping" }
            };

            HL.Log("Example of logging Lat-Long Geo locations using Google maps:");
            HL.Log(locations, "GoogleMaps");

            // Log a custom object of defined Class type
            var board = new Surfboard()
            {
                Name   = "Lib Tech Bowl",
                Length = 6.2,
                Volume = 30.8
            };

            HL.Log("Example of logging a custom object of defined Class type");
            HL.Log(board);

            // Log a custom object of anonymous type, with nested object
            var car = new
            {
                BrandName = "Seat",
                ModelName = "Mii",
                Engine    = new
                {
                    NumberOfCylinders = 3,
                    Acceleration      = 14.4
                },
                Color = "Red"
            };

            HL.Log("Example of logging an custom object of anonymous type");
            HL.Log(car);
        }