/// <summary>
        ///   Starts the application
        /// </summary>
        public static void Start()
        {
            #if DEBUG
            // Setup the logging view for Sentinel - http://sentinel.codeplex.com
            var sentinalTarget = new NLogViewerTarget()
            {
                Name = "sentinal",
                Address = "udp://127.0.0.1:9999"
            };
            var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
            LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
            LogManager.Configuration.LoggingRules.Add(sentinalRule);

            // Setup the logging view for Harvester - http://harvester.codeplex.com
            var harvesterTarget = new OutputDebugStringTarget()
            {
                Name = "harvester",
                Layout = new Log4JXmlEventLayout()
            };
            var harvesterRule = new LoggingRule("*", LogLevel.Trace, harvesterTarget);
            LogManager.Configuration.AddTarget("harvester", harvesterTarget);
            LogManager.Configuration.LoggingRules.Add(harvesterRule);

            LogManager.ReconfigExistingLoggers();
            #endif

            // Configure this.Log() for NLog
            Log.InitializeWith<NLogLog>();
        }
        public static void RegisterUdpLogger()
        {
            try
            {
                var udpTarget = new NLogViewerTarget();
                udpTarget.Address = "udp://127.0.0.1:20480";
                udpTarget.IncludeCallSite = true;
                udpTarget.IncludeSourceInfo = true;
                udpTarget.IncludeNLogData = true;
                udpTarget.IncludeNdc = true;
                udpTarget.Parameters.Add(new NLogViewerParameterInfo
                                             {
                                                 Name = "Exception",
                                                 Layout = "${exception:format=ToString}"
                                             });

                LogManager.Configuration.AddTarget(udpTarget.GetType().Name, udpTarget);
                LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, udpTarget));

                LogManager.ConfigurationReloaded += (sender, args) => RegisterUdpLogger();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                if (LogManager.ThrowExceptions)
                    throw;
            }
        }
Beispiel #3
0
        private void SetupLogging()
        {
            // Step 1. Create configuration object
            LoggingConfiguration configuration = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            FileTarget fileTarget = new FileTarget();
            configuration.AddTarget("file", fileTarget);

            NLogViewerTarget log_viewer_target = new NLogViewerTarget();
            log_viewer_target.Name = "viewer";
            log_viewer_target.Address = "udp://127.0.0.1:9999";
            configuration.AddTarget("viewer", log_viewer_target);

            // Step 3. Set target properties
            fileTarget.FileName = "${basedir}/file.txt";
            fileTarget.Layout = "${date} ${level} ${message}";

            // Step 4. Define rules
            LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, fileTarget);
            configuration.LoggingRules.Add(rule1);

            LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, log_viewer_target);
            configuration.LoggingRules.Add(rule2);

            // Step 5. Activate the configuration
            LogManager.Configuration = configuration;

            // Example usage
            log.Debug("Application started");
        }
Beispiel #4
0
        static Log()
        {
            #if DEBUG
              // Setup the logging view for Sentinel - http://sentinel.codeplex.com
              var sentinalTarget = new NLogViewerTarget
              {
            Name = "sentinal",
            Address = "udp://127.0.0.1:9999"
              };
              var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
              LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
              LogManager.Configuration.LoggingRules.Add(sentinalRule);

              // Setup the logging view for Harvester - http://harvester.codeplex.com
              var harvesterTarget = new OutputDebugStringTarget()
              {
            Name = "harvester",
            Layout = new Log4JXmlEventLayout()
              };
              var harvesterRule = new LoggingRule("*", LogLevel.Trace, harvesterTarget);
              LogManager.Configuration.AddTarget("harvester", harvesterTarget);
              LogManager.Configuration.LoggingRules.Add(harvesterRule);
            #endif

            LogManager.ReconfigExistingLoggers();

            Instance = LogManager.GetCurrentClassLogger();
        }
Beispiel #5
0
    static void Main(string[] args)
    {
        NLogViewerTarget target = new NLogViewerTarget();
        target.Address = "udp://localhost:4000";

        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

        Logger logger = LogManager.GetLogger("Example");
        logger.Trace("log message 1");
        logger.Debug("log message 2");
        logger.Info("log message 3");
        logger.Warn("log message 4");
        logger.Error("log message 5");
        logger.Fatal("log message 6");
    }
Beispiel #6
0
        /// <summary>
        ///     Add an NLogViewerTarget for the defined log level.
        /// </summary>
        /// <param name="name">Name of the logger.</param>
        /// <param name="target">Custom configured NLogViewerTarget.</param>
        /// <param name="minLogLevel">
        ///     Optional: Trace, Debug, Info, Warning, Error, Fatal, Off. If you make a type, then it
        ///     defaults to Off.
        /// </param>
        /// <param name="isAsync">Will the nLog viewer target be async or not?</param>
        public NLogLoggingService(string name, NLogViewerTarget target,
            LogLevel minLogLevel,
            bool isAsync = true)
            : this(name)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (minLogLevel == null)
            {
                throw new ArgumentNullException("minLogLevel");
            }

            ConfigureNLogViewerTarget(target, minLogLevel, isAsync);
        }
Beispiel #7
0
        public static void SetupNLog()
        {
            var config = new LoggingConfiguration();
            
            var tcpNetworkTarget = new NLogViewerTarget
            {
                Address = "tcp4://127.0.0.1:4505",
                Encoding = Encoding.UTF8,
                Name = "NLogViewer",
                IncludeNLogData = false
            };

            var tcpNetworkRule = new LoggingRule("*", LogLevel.Trace, tcpNetworkTarget);
            config.LoggingRules.Add(tcpNetworkRule);

            LogManager.Configuration = config;
        }
Beispiel #8
0
        private static void SetupLogging()
        {
            // Step 1. Create configuration object
            LoggingConfiguration configuration = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            NLogViewerTarget log_viewer_target = new NLogViewerTarget();
            configuration.AddTarget("viewer", log_viewer_target);

            // Step 3. Set target properties
            log_viewer_target.Name = "viewer";
            log_viewer_target.Address = "udp://127.0.0.1:9999";

            // Step 4. Define rules
            LoggingRule log_viewer_rule = new LoggingRule("*", LogLevel.Trace, log_viewer_target);
            configuration.LoggingRules.Add(log_viewer_rule);

            // Step 5. Activate the configuration
            LogManager.Configuration = configuration;
        }
        /// <summary>The enable remote udp logger.</summary>
        public void EnableRemoteUDPLogger()
        {
            if (string.IsNullOrWhiteSpace(this.targetIP))
            {
                return;
            }

            var config = LogManager.Configuration;

            var consoleTarget = new NLogViewerTarget
                                    {
                                        Name = "RemoteLog2Console",
                                        Address = string.Format("udp://{0}:7071", this.targetIP),
                                        Layout = "${event-context:item=messageType} ${longdate} | ${level:uppercase=true} | ${stacktrace} | ${message}"
                                    };

            config.AddTarget("RemoteLog2Console", consoleTarget);

            // <logger name="*" minlevel="Trace" writeTo="JRLog2Console" />
            config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));

            LogManager.Configuration = config;
        }
Beispiel #10
0
        // ==========================================
        //  LOGGING
        //  http://www.brutaldev.com/post/2012/03/27/Logging-setup-in-5-minutes-with-NLog
        // ==========================================
        public void SetupLogging()
        {
            LoggingConfiguration config = new LoggingConfiguration();

              // Build Targets ----------

              ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
              consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";

              FileTarget fileTarget = new FileTarget();
              fileTarget.FileName = "${basedir}/${shortdate}.log";
              fileTarget.Layout = "${message}";

              var viewerTarget = new NLogViewerTarget() {
            Name = "viewer",
            Address = "udp://localhost:9999",
            Layout = "${message}"
              };
              viewerTarget.Renderer.IncludeNLogData = false;

              // Add Targets ----------

              config.AddTarget("console", consoleTarget);
              config.AddTarget("file", fileTarget);
              config.AddTarget("viewer", viewerTarget);

              // Add Rules ----------

              LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget);
              config.LoggingRules.Add(rule1);

              LoggingRule rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
              config.LoggingRules.Add(rule2);

              LoggingRule rule3 = new LoggingRule("*", LogLevel.Debug, viewerTarget);
              config.LoggingRules.Add(rule3);

              LogManager.ReconfigExistingLoggers();
              LogManager.Configuration = config;
              logInfo("LOGGING", "STARTING LOGGING");
        }
Beispiel #11
0
        private void SetupLogging()
        {
            LoggingConfiguration configuration = new LoggingConfiguration();

            NLogViewerTarget log_viewer_target = new NLogViewerTarget();
            configuration.AddTarget("viewer", log_viewer_target);

            log_viewer_target.Name = "viewer";
            log_viewer_target.Address = "udp://127.0.0.1:9999";

            LoggingRule log_viewer_rule = new LoggingRule("*", LogLevel.Trace, log_viewer_target);
            configuration.LoggingRules.Add(log_viewer_rule);

            if (!string.IsNullOrEmpty(LogFile))
            {
                FileTarget file_target = new FileTarget();
                configuration.AddTarget("file", file_target);

                file_target.FileName = LogFile;
                file_target.Layout = "${message}";
                file_target.DeleteOldFileOnStartup = true;

                LoggingRule log_file_rule = new LoggingRule("*", LogLevel.Trace, file_target);
                configuration.LoggingRules.Add(log_file_rule);
            }

            // Step 5. Activate the configuration
            LogManager.Configuration = configuration;
        }
 static NLogViewerTarget GetNLogViewerLoggingTarget() {
     var log4View = new NLogViewerTarget {Address = "udp://127.0.0.1:12345", IncludeCallSite = true, AppInfo = "IntegrationTest"};
     log4View.Parameters.Add(new NLogViewerParameterInfo {Layout = "${exception:format=tostring}", Name = "Exception"});
     log4View.Parameters.Add(new NLogViewerParameterInfo {Layout = "${stacktrace}", Name = "StackTrace"});
     return log4View;
 }
Beispiel #13
0
        // ==========================================
        //  LOGGING
        //  http://www.brutaldev.com/post/2012/03/27/Logging-setup-in-5-minutes-with-NLog
        // ==========================================
        public void SetupLogging()
        {
            LoggingConfiguration config = new LoggingConfiguration();

              // Console ----------

              ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
              consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";

              config.AddTarget("console", consoleTarget);

              LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget);
              config.LoggingRules.Add(rule1);

              LoggingRule rule2 = new LoggingRule("*", LogLevel.Warn, consoleTarget);
              config.LoggingRules.Add(rule2);

              // File ----------

              if (null != logfile) {
            FileTarget fileTarget = new FileTarget();
            fileTarget.FileName = logfile;
            fileTarget.Layout = "${message}";

            config.AddTarget("file", fileTarget);

            LoggingRule rule3 = new LoggingRule("*", LogLevel.Debug, fileTarget);
            config.LoggingRules.Add(rule3);

            LoggingRule rule4 = new LoggingRule("*", LogLevel.Warn, fileTarget);
            config.LoggingRules.Add(rule4);
              }

              // View ----------

              var viewerTarget = new NLogViewerTarget() {
            Name = "viewer",
            Address = "udp://localhost:" + udpport,
            Layout = "${message}"
              };
              viewerTarget.Renderer.IncludeNLogData = false;
              config.AddTarget("viewer", viewerTarget);

              LoggingRule rule5 = new LoggingRule("*", LogLevel.Debug, viewerTarget);
              config.LoggingRules.Add(rule5);

              LoggingRule rule6 = new LoggingRule("*", LogLevel.Warn, viewerTarget);
              config.LoggingRules.Add(rule6);

              LogManager.ReconfigExistingLoggers();
              LogManager.Configuration = config;
              logInfo("LOGGING", "STARTING LOGGING");
        }
Beispiel #14
0
        // ==========================================
        //  LOGGING
        //  http://www.brutaldev.com/post/2012/03/27/Logging-setup-in-5-minutes-with-NLog
        // ==========================================
        public void SetupLogging()
        {
            LoggingConfiguration config = new LoggingConfiguration();

              // Build Targets ----------

              ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
              consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";

              FileTarget fileTarget = new FileTarget();
              fileTarget.FileName = "${basedir}/${shortdate}.log";
              fileTarget.Layout = "${message}";

              var sentinalTarget = new NLogViewerTarget() {
            Name = "sentinal",
            Address = "udp://127.0.0.1:9999"
              };

              // Add Targets ----------

              config.AddTarget("console", consoleTarget);
              config.AddTarget("file", fileTarget);
              config.AddTarget("sentinal", sentinalTarget);

              // Add Rules ----------

              LoggingRule rule1 = new LoggingRule("*", LogLevel.Debug, consoleTarget);
              config.LoggingRules.Add(rule1);

              LoggingRule rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
              config.LoggingRules.Add(rule2);

              LoggingRule rule3 = new LoggingRule("*", LogLevel.Debug, sentinalTarget);
              config.LoggingRules.Add(rule3);

              LogManager.Configuration = config;
        }
Beispiel #15
0
        private static void Main(string[] args)
        {
            LogManager.ThrowExceptions = true;

            #if DEBUG

            var log4viewTarget = new NLogViewerTarget()
            {
                Name = "log4view",
                Address = "udp://127.0.0.1:877",
                IncludeCallSite = true,
                IncludeSourceInfo = true
            };
            var log4viewRule = new LoggingRule("*", LogLevel.Trace, log4viewTarget);
            LogManager.Configuration.AddTarget("log4view", log4viewTarget);
            LogManager.Configuration.LoggingRules.Add(log4viewRule);

            var consoleTarget = new ColoredConsoleTarget()
            {
                Name = "console",
                Layout = "${date} ${callsite:includeSourcePath=false}: ${message}"
            };
            var consoleRule = new LoggingRule("*", LogLevel.Trace, consoleTarget);
            LogManager.Configuration.AddTarget("console", consoleTarget);
            LogManager.Configuration.LoggingRules.Add(consoleRule);

            LogManager.ReconfigExistingLoggers();

            #endif

            UnhandledExceptionDlg exDlg = new UnhandledExceptionDlg();

            #if RELEASE
            GaDotNet.Common.Data.ConfigurationSettings.GoogleAccountCode = "UA-28160719-3";
            #else
            GaDotNet.Common.Data.ConfigurationSettings.GoogleAccountCode = "UA-28160719-2";
            #endif
            GaDotNet.Common.Data.ConfigurationSettings.AppProductVersion = MainModel.ApplicationVersion;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            #region upgrade settings
            if (Settings.Default.MustUpgradeSettings)
            {
                try
                {
                    Settings.Default.Upgrade();
                    Settings.Default.MustUpgradeSettings = false;
                    Settings.Default.ShowFirstRunScreenV2 = true; // always make sure they see tutorial since it changed in v2
                    Settings.Default.Save();
                }
                catch (Exception)
                {
                    // never crash here. it's not worth it.
                    // this was crashing for me when I tried running a non-installed copy of HH (just copying the Release directory to another machine)
                }
            }
            #endregion

            //Application.Run(new TestForm());

            Application.Run(new MainForm());
        }
Beispiel #16
0
        /// <summary>
        ///     Adds or updates an NLog Viewer Target.
        /// </summary>
        /// <remarks>
        ///     This is a nice, clean and programmable way to send logging messages via the NLog Viewer Target.
        ///     Messages can be sent via Udp, Tcp or Http.
        ///     A good use of this is in Azure to programatically update a role without requiring it to recyle the entire role.
        ///     NOTE: The NLogViewerTarget will be wrapped in an AsyncWrapperTarget. Refer to the offical docs, if you don't know
        ///     what that means.
        /// </remarks>
        /// <param name="address">
        ///     Network address where the messages will be sent to. eg. udp://1.2.3.4:9999). Refer to NLog docs
        ///     for all the  address options.
        /// </param>
        /// <param name="minimumLogLevel">
        ///     Optional: Trace, Debug, Info, Warning, Error, Fatal, Off. If you make a type, then it
        ///     defaults to Off.
        /// </param>
        /// <param name="isAsync">Will the nLog viewer target be async or not?</param>
        /// <see cref="https://github.com/nlog/NLog/wiki/NLogViewer-target" />
        public void ConfigureNLogViewerTarget(string address,
            LogLevel minimumLogLevel,
            bool isAsync = true)
        {
            if (string.IsNullOrWhiteSpace(address))
            {
                throw new ArgumentNullException("address");
            }

            if (minimumLogLevel == null)
            {
                throw new ArgumentNullException("minimumLogLevel");
            }

            var target = new NLogViewerTarget
            {
                Name = "SimpleLogging-nLogViewerTarget-" + DateTime.Now.Ticks,
                Address = address,
                IncludeNLogData = false
            };

            ConfigureNLogViewerTarget(target, minimumLogLevel, isAsync);
        }
Beispiel #17
0
        /// <summary>
        ///     Adds or updates an NLog Viewer Target.
        /// </summary>
        /// <remarks>
        ///     This is a nice, clean and programmable way to send logging messages via the NLog Viewer Target.
        ///     Messages can be sent via Udp, Tcp or Http.
        ///     A good use of this is in Azure to programatically update a role without requiring it to recyle the entire role.
        ///     NOTE: The NLogViewerTarget will be wrapped in an AsyncWrapperTarget. Refer to the offical docs, if you don't know
        ///     what that means.
        /// </remarks>
        /// <param name="target">Custom configured NLogViewerTarget.</param>
        /// <param name="minimumLogLevel">
        ///     Optional: Trace, Debug, Info, Warning, Error, Fatal, Off. If you make a type, then it
        ///     defaults to Off.
        /// </param>
        /// <param name="isAsync">Will the nLog viewer target be async or not?</param>
        /// <see cref="https://github.com/nlog/NLog/wiki/NLogViewer-target" />
        public void ConfigureNLogViewerTarget(NLogViewerTarget target,
            LogLevel minimumLogLevel,
            bool isAsync = true)
        {
            // Code Reference: http://stackoverflow.com/questions/7471490/add-enable-and-disable-nlog-loggers-programmatically

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (minimumLogLevel == null)
            {
                throw new ArgumentNullException("minimumLogLevel");
            }

            if (LogManager.Configuration == null)
            {
                LogManager.Configuration = new LoggingConfiguration();
            }

            Target loggingRuleTarget;

            if (isAsync)
            {
                var originalTargetName = string.IsNullOrWhiteSpace(target.Name)
                        ? "unamed"
                        : target.Name;

                // Just trying to stick with the naming conventions.
                target.Name = string.Format("{0}_Wrapped", originalTargetName);

                // We need to make sure we wrap the target in an Async Target Wrapper.
                loggingRuleTarget = new AsyncTargetWrapper(target)
                {
                    Name = originalTargetName
                };
                LogManager.Configuration.AddTarget(originalTargetName, loggingRuleTarget);
            }
            else
            {
                loggingRuleTarget = target;
            }

            var loggingRule = new LoggingRule("*", minimumLogLevel, loggingRuleTarget);
            LogManager.Configuration.LoggingRules.Add(loggingRule);

            // Make sure all the loggers are refreshed and re-configured nicely.
            LogManager.ReconfigExistingLoggers();
        }