Ejemplo n.º 1
0
        static Log()
        {
            LogManager.ThrowExceptions = true;

//TODO remove sentinel loggin when deploying final version
//#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();
        }
        public void Configure()
        {
            // See: https://github.com/nlog/NLog/wiki/Configuration-API

            // Step 1. Create configuration object
            var config = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            // See http://sentinel.codeplex.com/ for a log viewer
            var viewerTarget = new NLogViewerTarget();

            config.AddTarget("viewer", viewerTarget);

            var fileTarget = new FileTarget();

            config.AddTarget("file", fileTarget);

            // Step 3. Set target properties
            viewerTarget.Layout  = _logLayoutPattern;
            viewerTarget.Address = "udp://127.0.0.1:9999";
            fileTarget.FileName  = _logFileNamePattern;
            fileTarget.Layout    = _logLayoutPattern;

            // Step 4. Define rules
            var rule1 = new LoggingRule("*", LogLevel.Debug, viewerTarget);

            config.LoggingRules.Add(rule1);

            var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);

            config.LoggingRules.Add(rule2);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        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;
                }
            }
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public static void Init(Target[] appSpecificTargets)
        {
            LoggingConfiguration config = new LoggingConfiguration();

            // Targets
            FileTarget logFile = new FileTarget("logFile")
            {
                FileName = GetLogFileName()
            };
            // DebuggerTarget is disabled because it significantly slows down performance
            // DebuggerTarget debugOutput = new DebuggerTarget("debugOutput");
            NLogViewerTarget viewer = new NLogViewerTarget("viewer")
            {
                Address           = "udp://127.0.0.1:9999",
                IncludeSourceInfo = true
            };

            config.AddRule(LogLevel.Info, LogLevel.Fatal, logFile);
            // config.AddRule(LogLevel.Debug, LogLevel.Fatal, debugOutput);
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, viewer);
            foreach (Target t in appSpecificTargets)
            {
                config.AddRule(LogLevel.Info, LogLevel.Fatal, t);
            }

            LogManager.Configuration = config;
        }
Ejemplo n.º 7
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");
        }
Ejemplo n.º 8
0
        static Log()
        {
#if DEBUG
            // Setup the logging view for Sentinel - http://sentinel.codeplex.com
            var sentinelTarget = new NLogViewerTarget()
            {
                Name            = "sentinel",
                Address         = "udp://127.0.0.1:9999",
                IncludeNLogData = false
            };
            var sentinelRule = new LoggingRule("*", LogLevel.Trace, sentinelTarget);
            LogManager.Configuration.AddTarget("sentinel", sentinelTarget);
            LogManager.Configuration.LoggingRules.Add(sentinelRule);

            // Setup the logging view for Harvester - http://harvester.codeplex.com

            /*
             * var harvesterTarget = new OutputDebugStringTarget() {
             *  Name = "harvester",
             *  Layout = "${log4jxmlevent:includeNLogData=false}"
             * };
             * var harvesterRule = new LoggingRule("*", LogLevel.Trace, harvesterTarget);
             * LogManager.Configuration.AddTarget("harvester", harvesterTarget);
             * LogManager.Configuration.LoggingRules.Add(harvesterRule);
             */
#endif

            LogManager.ReconfigExistingLoggers();
            Instance = LogManager.GetCurrentClassLogger();
        }
Ejemplo n.º 9
0
        public void Configure()
        {
            // See: https://github.com/nlog/NLog/wiki/Configuration-API

            // Step 1. Create configuration object
            var config = new LoggingConfiguration();

            // Step 2. Create targets and add them to the configuration
            // See http://sentinel.codeplex.com/ for an log viewer
            var viewerTarget = new NLogViewerTarget();

            config.AddTarget("viewer", viewerTarget);

            var fileTarget = new FileTarget();

            config.AddTarget("file", fileTarget);

            // Step 3. Set target properties
            viewerTarget.Layout  = @"${callsite} ${message} ${onexception:Exception information\:${exception:format=type,message,method,StackTrace:maxInnerExceptionLevel=5:innerFormat=type,message,method,StackTrace}";
            viewerTarget.Address = "udp://127.0.0.1:9999";
            fileTarget.FileName  = _logFileNamePattern;
            fileTarget.Layout    = @"${callsite} ${message} ${onexception:Exception information\:${exception:format=type,message,method,StackTrace:maxInnerExceptionLevel=5:innerFormat=type,message,method,StackTrace}";

            // Step 4. Define rules
            var rule1 = new LoggingRule("*", LogLevel.Debug, viewerTarget);

            config.LoggingRules.Add(rule1);

            var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);

            config.LoggingRules.Add(rule2);

            // Step 5. Activate the configuration
            LogManager.Configuration = config;
        }
Ejemplo n.º 10
0
        private static void SetupSelfLogging()
        {
            if (!LogazmicSettings.Instance.EnableSelfLogging)
            {
                return;
            }

            var config = new LoggingConfiguration();

            #region tcp

            var tcpNetworkTarget = new NLogViewerTarget
            {
                Address         = "tcp4://127.0.0.1:" + LogazmicSettings.Instance.SelfLoggingPort,
                Encoding        = Encoding.UTF8,
                Name            = "NLogViewer",
                IncludeNLogData = false
            };
            var tcpNetworkRule = new LoggingRule("*", LogLevel.Trace, tcpNetworkTarget);
            config.LoggingRules.Add(tcpNetworkRule);

            #endregion

            NLog.LogManager.Configuration = config;
        }
Ejemplo n.º 11
0
        static Log()
        {
            //LogManager.Configuration = new XmlLoggingConfiguration(AppDomain.CurrentDomain.BaseDirectory + @"Main\NLog\NLog.xml", true);
            LogManager.Configuration = new XmlLoggingConfiguration(AppDomain.CurrentDomain.BaseDirectory + @"Main\NLog\NLog.config", true);
            //LoggingConfiguration config = new LoggingConfiguration();


            var sentinalTarget = new NLogViewerTarget()
            {
                Name            = "sentinal",
                Address         = "udp://127.0.0.1:9999",
                IncludeNLogData = true
            };
            var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);

            LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
            LogManager.Configuration.LoggingRules.Add(sentinalRule);

            var harvesterTarget = new OutputDebugStringTarget()
            {
                Name   = "harvester",
                Layout = "${log4jxmlevent:includeNLogData=false}"
            };
            var harvesterRule = new LoggingRule("*", LogLevel.Trace, harvesterTarget);

            LogManager.Configuration.AddTarget("harvester", harvesterTarget);
            LogManager.Configuration.LoggingRules.Add(harvesterRule);

            LogManager.ReconfigExistingLoggers();

            Instance = LogManager.GetCurrentClassLogger();
        }
Ejemplo n.º 12
0
            public static Target Target()
            {
                var targetNLogViewer = new NLogViewerTarget();

                targetNLogViewer.Address = ApplicationConfig.Instance.LogServer;

                return(targetNLogViewer);
            }
        /// <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,
                                              string minimumLogLevel = "debug",
                                              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 (string.IsNullOrWhiteSpace(minimumLogLevel))
            {
                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;
            }

            LogLevelType logLevel;

            Enum.TryParse(minimumLogLevel, true, out logLevel);

            var loggingRule = new LoggingRule("*", TryParseToLogLevel(logLevel), loggingRuleTarget);

            LogManager.Configuration.LoggingRules.Add(loggingRule);

            // Make sure all the loggers are refreshed and re-configured nicely.
            LogManager.ReconfigExistingLoggers();
        }
Ejemplo n.º 14
0
        public void Initialize(LogLevel logLevel)
        {
            var          config    = new LoggingConfiguration();
            const string logLayout = "${longdate} [${level:uppercase=true}] Thread: [${threadid}]${newline}" +
                                     "${logger}:${callsite-linenumber} ${when:when=length('${threadname}') > 0: [${threadname}]}${newline}" +
                                     "${message}${newline}" +
                                     "${when:when=length('${exception}') > 0: ${exception}${newline}}";

            if (logLevel == LogLevel.Debug)
            {
                _consoleTarget    = new ColoredConsoleTarget();
                _debuggerTarget   = new DebuggerTarget();
                _nLogViewerTarget = new NLogViewerTarget
                {
                    Name              = "sentinel",
                    Address           = "udp://127.0.0.1:9999",
                    IncludeNLogData   = true,
                    IncludeSourceInfo = true,
                };

                var sentinelRule = new LoggingRule("*", LogLevel.Trace, _nLogViewerTarget);
                config.AddTarget("sentinel", _nLogViewerTarget);
                config.LoggingRules.Add(sentinelRule);
                config.AddTarget("console", _consoleTarget);
                config.AddTarget("debugger", _debuggerTarget);
                _consoleTarget.Layout  = @"${date:format=HH\\:MM\\:ss} ${logger} [${threadid}]:${message} ${exception}";
                _debuggerTarget.Layout = logLayout;

                var consoleRule = new LoggingRule("*", LogLevel.Debug, _consoleTarget);
                config.LoggingRules.Add(consoleRule);

                var debuggerRule = new LoggingRule("*", LogLevel.Debug, _debuggerTarget);
                config.LoggingRules.Add(debuggerRule);
            }
            else
            {
                _fileTarget = new FileTarget
                {
                    ArchiveAboveSize             = 2097152,
                    ArchiveEvery                 = FileArchivePeriod.Day,
                    ArchiveNumbering             = ArchiveNumberingMode.Rolling,
                    MaxArchiveFiles              = 5,
                    EnableArchiveFileCompression = true,
                    FileName = _storageLocationProvider.LogFile,
                    Layout   = logLayout,
                };

                config.AddTarget("file", _fileTarget);
                var fileRule = new LoggingRule("*", logLevel, _fileTarget);
                config.LoggingRules.Add(fileRule);
            }

            LogManager.Configuration = config;
            LogManager.ReconfigExistingLoggers();
        }
Ejemplo n.º 15
0
        private static void ConfigureLogging()
        {
            bool   bBuiltIn = false;
            string logPath  = Path.Combine(ApplicationDirectory, "logs");

            Directory.CreateDirectory(logPath);


            try { File.Delete(Path.Combine(logPath, "7dtdmanager.log.20")); }
            catch { }
            for (int i = 19; i >= 0; i--)
            {
                try { File.Move(Path.Combine(logPath, "7dtdmanager.log." + i.ToString()), Path.Combine(logPath, "7dtdmanager.log." + (i + 1).ToString())); }
                catch { }
            }
            try { File.Move(Path.Combine(logPath, "7dtdmanager.log"), Path.Combine(logPath, "7dtdmanager.log.0")); }
            catch { }

            if (!File.Exists(Path.Combine(ApplicationDirectory, "nlog.config")))
            {
                LoggingConfiguration config = new LoggingConfiguration();


                FileTarget fileTarget = new FileTarget();

                config.AddTarget("file", fileTarget);
                fileTarget.FileName = "${basedir}/logs/7dtdmanager.log";
                fileTarget.Encoding = Encoding.UTF8;
                fileTarget.Layout   = "${longdate}|${level:uppercase=true}|${threadid}|${logger}|${message}";

                // AsyncTargetWrapper asyncFileTarget = new AsyncTargetWrapper(fileTarget, 5000, AsyncTargetWrapperOverflowAction.Discard);

                NLogViewerTarget nlogTarget = new NLogViewerTarget();
                nlogTarget.Address = "udp://127.0.0.1:9999";
#if DEBUG
                // To nicely view the nlogtarget i prefer Log4View (free) http://www.log4view.de/log4view/
                config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget));
                config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, nlogTarget));
#else
                config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));
                config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, new ConsoleTarget()));
#endif
                // config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, nlogTarget));
                //config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, nlogTarget));
                LogManager.Configuration = config;
                bBuiltIn = true;
            }
            LogManager.EnableLogging();
            logger = LogManager.GetCurrentClassLogger();
            logger.Info(">>> START 7dtdmanager Version {0}", Assembly.GetEntryAssembly().FullName);
            logger.Info("Using {0} configuration", (bBuiltIn ? "Builtin" : "Configfile"));
        }
        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);
        }
        /// <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="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>
        public NLogLoggingService(string name, NLogViewerTarget target,
                                  string minimumLogLevel = "debug",
                                  bool isAsync           = true)
            : this(name)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (string.IsNullOrWhiteSpace(minimumLogLevel))
            {
                throw new ArgumentNullException("minimumLogLevel");
            }

            ConfigureNLogViewerTarget(target, minimumLogLevel, isAsync);
        }
        /// <summary>
        /// reconfigure logger for udp target
        /// </summary>
        static Log()
        {
            var sentinalTarget = new NLogViewerTarget()
            {
                Name            = "sentinal",
                Address         = "udp://127.0.0.1:9999",
                IncludeNLogData = false
            };
            var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);

            LogManager.Configuration.AddTarget("sentinal", sentinalTarget);
            LogManager.Configuration.LoggingRules.Add(sentinalRule);

            LogManager.ReconfigExistingLoggers();

            Instance = LogManager.GetCurrentClassLogger();
        }
Ejemplo n.º 19
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");
    }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        public NLogLogger()
        {
            #if DEBUG
            // Setup the logging view for Sentinel - http://sentinel.codeplex.com
            var sentinalTarget = new NLogViewerTarget()
            {
                Name            = "sentinel",
                Address         = "udp://127.0.0.1:9999",
                IncludeNLogData = false
            };
            var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
            LogManager.Configuration.AddTarget("sentinel", sentinalTarget);
            LogManager.Configuration.LoggingRules.Add(sentinalRule);
            #endif

            LogManager.ReconfigExistingLoggers();
            Instance = LogManager.GetCurrentClassLogger();
        }
Ejemplo n.º 22
0
        public static void SetupNLog(int port = 4505)
        {
            var config = new LoggingConfiguration();

            var tcpNetworkTarget = new NLogViewerTarget
            {
                Address         = $"tcp4://127.0.0.1:{port}",
                Encoding        = Encoding.UTF8,
                Name            = "NLogViewer",
                IncludeNLogData = false
            };

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

            config.LoggingRules.Add(tcpNetworkRule);

            LogManager.Configuration = config;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Log Routine - Setup some basic configuration for NLog
        /// Also includes the configuration of Sentinel
        /// </summary>
        static Log()
        {
            #region DEBUG STUFF
#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",
                IncludeNLogData = false
            };
            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 = "${log4jxmlevent:includeNLogData=false}"
            };
            var harvesterRule = new LoggingRule("*", LogLevel.Trace, harvesterTarget);
            LogManager.Configuration.AddTarget("harvester", harvesterTarget);
            LogManager.Configuration.LoggingRules.Add(harvesterRule);
#endif
            #endregion

            // Setup the logging view for Sentinel - http://sentinel.codeplex.com
            var sentinalTarget = new NLogViewerTarget()
            {
                Name            = Properties.Settings.Default.SentinelTarget,
                Address         = $"{Properties.Settings.Default.SentinelProtocol}://{Properties.Settings.Default.SentinelHost}:{Properties.Settings.Default.SentinelPort}",
                IncludeNLogData = Properties.Settings.Default.SentinelNLogData
            };
            var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);
            LogManager.Configuration.AddTarget(Properties.Settings.Default.SentinelTarget, sentinalTarget);
            LogManager.Configuration.LoggingRules.Add(sentinalRule);

            LogManager.ReconfigExistingLoggers();

            Instance = LogManager.GetCurrentClassLogger();
        }
Ejemplo n.º 24
0
        static Log()
        {
            Instance = LogManager.GetCurrentClassLogger();
            return;

            // Setup the logging view for Sentinel - http://sentinel.codeplex.com
            var sentinalTarget = new NLogViewerTarget()
            {
                Name    = "dictionary",
                Address = "udp://127.0.0.1:9999"
            };
            var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);

            LogManager.Configuration.AddTarget("dictionary", sentinalTarget);
            LogManager.Configuration.LoggingRules.Add(sentinalRule);

            LogManager.ReconfigExistingLoggers();

            Instance = LogManager.GetCurrentClassLogger();
        }
            public void GivenANameAndATarget_Constructor_IsInstantiatedWithATwoTarget()
            {
                // Arrange.
                const string name   = "blah";
                var          target = new NLogViewerTarget
                {
                    Address         = "udp://1.2.3.4:9999",
                    IncludeNLogData = false
                };

                // Act.
                var service = new NLogLoggingService(name, target);

                // Assert.
                service.ShouldNotBe(null);
                service.Name.ShouldBe(name);
                LogManager.Configuration.ShouldNotBe(null);
                LogManager.Configuration.AllTargets.ShouldNotBeEmpty();
                LogManager.Configuration.AllTargets.Count.ShouldBe(2);
                LogManager.Configuration.LoggingRules.ShouldNotBeEmpty();
                LogManager.Configuration.LoggingRules.Count.ShouldBe(1);
            }
Ejemplo n.º 26
0
        public static void Default()
        {
            // 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;
        }
Ejemplo n.º 27
0
        public LogService()
        {
            //LogManager.Configuration = new XmlLoggingConfiguration(@"\\variancom\va_data$\filedata\ProgramData\Vision\PublishedScripts\NLog.config");
            //#if DEBUG
            var config = new LoggingConfiguration();


            // Setup the logging view for Sentinel - http://sentinel.codeplex.com
            var sentinalTarget = new NLogViewerTarget()
            {
                Name            = "sentinal",
                Address         = "udp://10.221.45.179:9999",
                IncludeNLogData = false
            };
            var sentinalRule = new LoggingRule("*", LogLevel.Trace, sentinalTarget);

            config.AddTarget("sentinal", sentinalTarget);
            config.LoggingRules.Add(sentinalRule);

            //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 = "${log4jxmlevent:includeNLogData=false}"
            //};
            //var harvesterRule = new LoggingRule("*", LogLevel.Trace, harvesterTarget);
            //LogManager.Configuration.AddTarget("harvester", harvesterTarget);
            //LogManager.Configuration.LoggingRules.Add(harvesterRule);
            //#endif

            //LogManager.ReconfigExistingLoggers();

            LogManager.Configuration = config;
            Instance = LogManager.GetCurrentClassLogger();
        }
Ejemplo n.º 28
0
        public static void SetupLogger()
        {
            lock (LoggerLock)
            {
                if (!IsLoggerInitialized)
                {
                    LoggingConfiguration config = new LoggingConfiguration();

                    // Targets
                    DebuggerTarget   debugOutput = new DebuggerTarget("debugOutput");
                    NLogViewerTarget viewer      = new NLogViewerTarget("viewer")
                    {
                        Address           = "udp://127.0.0.1:9999",
                        IncludeSourceInfo = true
                    };

                    config.AddRule(LogLevel.Debug, LogLevel.Fatal, debugOutput);
                    config.AddRule(LogLevel.Trace, LogLevel.Fatal, viewer);
                    LogManager.Configuration = config;
                    IsLoggerInitialized      = true;
                }
            }
        }
Ejemplo n.º 29
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);
        }
        /// <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;
        }