A core logger that can be used to write log messages to the console and or a log file.
Inheritance: ILogger
Ejemplo n.º 1
0
        /// <summary>
        /// Enable logging, useful for debugging applications.
        /// </summary>
        private void EnableLogging()
        {
            //We will create the log file in the local documents directory
            string logFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "NetworkCommsLog.txt");
            ChatApplication.AppendLineToChatHistory("Logging enabled to " + logFileName);

            ILogger logger = new LiteLogger(LiteLogger.LogMode.LogFileOnly, logFileName);
            NetworkComms.EnableLogging(logger);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                Console.SetBufferSize(160, 500);
                Console.SetWindowSize(160, 25);
            }
            catch (Exception) { }

            Thread.CurrentThread.Name = "MainThread";

            if (false)
            {
                ILogger logger = new LiteLogger(LiteLogger.LogMode.ConsoleAndLogFile, "DebugTests_" + NetworkComms.NetworkIdentifier + ".txt");
                NetworkComms.EnableLogging(logger);

                //Incase we run the DFS test we will also enable logging for that
                DistributedFileSystem.DFS.EnableLogging(logger);
            }

            //NetworkComms.EnablePacketCheckSumValidation = true;

            DebugTest.RunExample(args);
            //BasicSend.RunExample();
            //AliveTest.RunExample();
            //DebugTest.RunExample();
            //DFSTest.RunExample();
            //BandwidthLoadTest.RunExample();
            //BluetoothTest.RunExample();
            //NumConnectionLoadTest.RunExample();
            //ThreadPoolTest.RunExample();
            //SSLTest.RunExample();
            //NestedPacketTest.RunExample();
            //PeerDiscoveryTest.RunExample();
            //SelfConnectTest.RunExample();
            //SymEncryptionTest.RunExample();
            //UnmanagedUDPBroadcast.RunExample();

            //LogAnalyser log = new LogAnalyser(@"C:\Users\Karnifexx\Documents\Visual Studio 2010\Projects\networkcomms.net\DebugTests\bin\Debug\DebugTests_e-P76M-6LkSFyUFFlnU0qA.txt");
            //log.LinesWithMatch(new string[] { "Received packet of type 'ConnectionSetup'" }, "matchLog4.txt");
            //log.ThreadPoolInfo("threadPool.csv");
            //log.DataSendReceive(10, "sendReceiveStats.csv");
        }
Ejemplo n.º 3
0
        private static void SelectLogging()
        {
            //If the user wants to enable logging 
            Console.WriteLine("To enable comms logging press 'y'. To leave logging disabled and continue press any other key.\n");

            if (Console.ReadKey(true).Key == ConsoleKey.Y)
            {
                //Select the logger to use
                Console.WriteLine("Please select the logger to use:\n1 - NetworkComms.Net LiteLogger\n2 - External NLog Logger");

                //Parse the user input for the selected logger
                int selectedLogger;
                while (true)
                {
                    bool parseSucces = int.TryParse(Console.ReadKey(true).KeyChar.ToString(), out selectedLogger);
                    if (parseSucces && selectedLogger <= 2 && selectedLogger > 0) break;
                    Console.WriteLine("Invalid logger choice. Please try again.");
                }

                //Set the desired logger
                ILogger logger;
                if (selectedLogger == 1)
                {
                    Console.WriteLine(" ... selected NetworkComms.Net LiteLogger.\n");

                    //////////////////////////////////////////////////////////////////////
                    //// SIMPLE CONSOLE ONLY LOGGING
                    //////////////////////////////////////////////////////////////////////
                    //ILogger logger = new LiteLogger(LiteLogger.LogMode.ConsoleOnly);
                    //NetworkComms.EnableLogging(logConfig);

                    //////////////////////////////////////////////////////////////////////
                    //// THE FOLLOWING CONFIG LOGS TO BOTH A FILE AND CONSOLE
                    //////////////////////////////////////////////////////////////////////
                    string logFileName = "ExamplesConsoleLog_" + NetworkComms.NetworkIdentifier + ".txt";
                    logger = new LiteLogger(LiteLogger.LogMode.ConsoleAndLogFile, logFileName);
                }
                else if (selectedLogger == 2)
                {
                    Console.WriteLine(" ... selected external NLog logger.\n");

                    //We create an instance of the NLogLogger class which uses a default implementation of 
                    //the ILogger interface provided with NetworkComms.Net
                    logger = new NLogLogger();
                }
                else
                    throw new Exception("Unable to determine selected connection type.");

                //Enable logging using the selected logger
                NetworkComms.EnableLogging(logger);

                //In case we run the DFS test we will also enable logging for that
                DistributedFileSystem.DFS.EnableLogging(logger);

                //We can write to our logger from an external application as well
                NetworkComms.Logger.Info("NetworkComms.Net logging enabled.");
            }
        }