IBusControl ConfigureBus(IConfigurationRoot configuration)
        {
            var logFactory = new NLog.LogFactory();

            logFactory.LoadConfiguration("nlog.config");

            RabbitMqConfig configFromfile = configuration.GetSection("RabbitMq").Get <RabbitMqConfig>();

            return(Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                cfg.Host(configFromfile.HostUrl, (hostCfg) =>
                {
                    hostCfg.Username(configFromfile.Username);
                    hostCfg.Password(configFromfile.Password);
                });

                cfg.ReceiveEndpoint("user_created", e =>
                {
                    e.Consumer <UserCreatedConsumer>(() =>
                    {
                        return new UserCreatedConsumer(new Common.LoggerHelper(logFactory.GetLogger("UserCreatedConsumer")));
                    });
                });
            }));
        }
        public void LogglyTargetContextPropertyTest()
        {
            NLog.LogFactory logFactory = new NLog.LogFactory();
            NLog.Config.LoggingConfiguration logConfig = CreateConfigurationFromString(
                @"<nlog throwExceptions='true'>
                    <extensions>
	                    <add assembly='NLog.Targets.Loggly' />
                    </extensions>
                    <targets>
                        <target name='Loggly' type='Loggly' layout='${message}' taskDelayMilliseconds='10'>
                            <contextproperty name='hello' layout='${logger}' />
                        </target>
                    </targets>
	                <rules>
	                    <logger name='*' minlevel='Info' writeTo='Loggly' />
                    </rules>
                  </nlog>", logFactory);
            var logglyTarget     = logConfig.FindTargetByName("Loggly") as NLog.Targets.LogglyTarget;
            var logglyClientMock = new LogglyClientMock();

            logglyTarget.ClientFactory = () => logglyClientMock;
            logFactory.Configuration   = logConfig;
            NLog.Logger logger = logFactory.GetLogger(MethodInfo.GetCurrentMethod().Name);
            logger.Info("Hello World");
            logglyClientMock.LogWritten.WaitOne(1000);
            Assert.AreEqual(1, logglyClientMock.LogglyEvents.Count);
            Assert.Contains("hello", logglyClientMock.LogglyEvents[0].Data.KeyList);
            Assert.AreEqual(MethodInfo.GetCurrentMethod().Name, logglyClientMock.LogglyEvents[0].Data["hello"]);
        }
示例#3
0
 public NLogTests(NLogConfiguration configuration = null)
 {
     factory = LoggerBuilders.BuildNLogFactory(configuration ?? new NLogConfiguration {
         KeepFileOpen = true
     });
     logger = factory.GetLogger(nameof(IAuditLogger));
 }
        public void LogglyTargetTagsTest()
        {
            NLog.LogFactory logFactory = new NLog.LogFactory();
            NLog.Config.LoggingConfiguration logConfig = CreateConfigurationFromString(
                @"<nlog throwExceptions='true'>
                    <extensions>
	                    <add assembly='NLog.Targets.Loggly' />
                    </extensions>
                    <targets>
                        <target name='Loggly' type='Loggly' layout='${message}'>
                            <tag name='hello' />
                            <tag name='${logger}' />
                        </target>
                    </targets>
	                <rules>
	                    <logger name='*' minlevel='Info' writeTo='Loggly' />
                    </rules>
                  </nlog>", logFactory);
            var logglyTarget     = logConfig.FindTargetByName("Loggly") as NLog.Targets.LogglyTarget;
            var logglyClientMock = new LogglyClientMock();

            logglyTarget.ClientFactory = () => logglyClientMock;
            logFactory.Configuration   = logConfig;
            NLog.Logger logger = logFactory.GetLogger(MethodInfo.GetCurrentMethod().Name);
            logger.Info("Hello World");
            Assert.AreEqual(1, logglyClientMock.LogglyEvents.Count);
            Assert.AreEqual(2, logglyClientMock.LogglyEvents[0].Options.Tags.Count);
            Assert.AreEqual("hello", logglyClientMock.LogglyEvents[0].Options.Tags[0].Value);
            Assert.AreEqual(MethodInfo.GetCurrentMethod().Name, logglyClientMock.LogglyEvents[0].Options.Tags[1].Value);
        }
        public void LogglyTargetMdlcTest()
        {
            NLog.LogFactory logFactory = new NLog.LogFactory();
            NLog.Config.LoggingConfiguration logConfig = CreateConfigurationFromString(
                @"<nlog throwExceptions='true'>
                    <extensions>
	                    <add assembly='NLog.Targets.Loggly' />
                    </extensions>
                    <targets>
                        <target name='Loggly' type='Loggly' layout='${message}' includeMdlc='true'>
                        </target>
                    </targets>
	                <rules>
	                    <logger name='*' minlevel='Info' writeTo='Loggly' />
                    </rules>
                  </nlog>", logFactory);
            var logglyTarget     = logConfig.FindTargetByName("Loggly") as NLog.Targets.LogglyTarget;
            var logglyClientMock = new LogglyClientMock();

            logglyTarget.ClientFactory = () => logglyClientMock;
            logFactory.Configuration   = logConfig;
            NLog.Logger logger = logFactory.GetLogger(MethodInfo.GetCurrentMethod().Name);
            using (NLog.MappedDiagnosticsLogicalContext.SetScoped("hello", logger.Name))
            {
                logger.Info("Hello World");
                Assert.AreEqual(1, logglyClientMock.LogglyEvents.Count);
                Assert.Contains("hello", logglyClientMock.LogglyEvents[0].Data.KeyList);
                Assert.AreEqual(MethodInfo.GetCurrentMethod().Name, logglyClientMock.LogglyEvents[0].Data["hello"]);
            }
        }
示例#6
0
        public static ILogger GetLogger(string name)
        {
            var factory = new NLog.LogFactory();
            var logger  = factory.GetLogger(name);

            return(new Logger(logger));
        }
示例#7
0
        /// <summary>
        /// Get type specific logger, or fallback logger.
        /// </summary>
        /// <param name="line"></param>
        /// <returns>logger or null if has been disposed</returns>
        NLog.ILogger Logger(ILine line)
        {
            NLog.LogFactory _logFactory = logFactory;
            if (_logFactory == null)
            {
                return(null);
            }
            ILine type = line.FindTypeKey();

            if (type is ILineType lineType && lineType.Type != null)
            {
                return(_logFactory.GetLogger(lineType.Type.FullName, lineType.Type));
            }
            if (type is ILineParameter lineParameter && lineParameter.ParameterValue != null)
            {
                return(_logFactory.GetLogger(lineParameter.ParameterValue));
            }
            return(fallbackLogger);
        }
        static void Main(string[] args)
        {
            var config = new NLog.Config.LoggingConfiguration();

            using (var fluentdTarget = new NLog.Targets.Fluentd())
            {
                fluentdTarget.Layout = new NLog.Layouts.SimpleLayout("${longdate}|${level}|${callsite}|${logger}|${message}");
                config.AddTarget("fluentd", fluentdTarget);
                config.LoggingRules.Add(new NLog.Config.LoggingRule("demo", NLog.LogLevel.Debug, fluentdTarget));
                var loggerFactory = new NLog.LogFactory(config);
                var logger        = loggerFactory.GetLogger("demo");
                logger.Info("Hello World!");
            }
        }
示例#9
0
        /// <summary>
        /// The entry point of the SynchroFeed.Listener application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            var logFactory = new NLog.LogFactory();
            var logger     = logFactory.GetLogger("SynchroFeed.Listener.Program");

            logger.Log(NLog.LogLevel.Info, "SynchroFeed.Listener Starting");
            logger.Log(NLog.LogLevel.Debug, $"args length: {args.Length}");
            foreach (var arg in args)
            {
                logger.Log(NLog.LogLevel.Debug, $"arg: {arg}");
            }
            var commandLineApp = new ListenerCommandLine();

            Environment.ExitCode = Execute(commandLineApp, logger);
        }
示例#10
0
        protected void Application_Start()
        {
            var factory = new NLog.LogFactory();

            var logger = factory.GetLogger("Default");

            logger.Debug("Iniciando app...");

            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();

            AreaRegistration.RegisterAllAreas();

            // Use LocalDB for Entity Framework by default
            Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            logger.Debug("App Iniciada");
        }
示例#11
0
        protected void Application_Start()
        {
            var factory = new NLog.LogFactory();

            var logger = factory.GetLogger("Default");

            logger.Debug("Iniciando app...");

            HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();

            AreaRegistration.RegisterAllAreas();

            // Use LocalDB for Entity Framework by default
            Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            logger.Debug("App Iniciada");
        }
示例#12
0
        static Program()
        {
            string mysql_conn = "";

            logFactory = NLog.LogManager.LoadConfiguration("nlog.config");
            logger     = logFactory.GetLogger("CumulateHourlyApp");
#if DEBUG
            Console.WriteLine("DEBUG MODE");
            string influx_hostname = "http://192.168.0.40:8086";
            string influx_username = "******";
            string influx_password = "******";


            mysql_conn   = PeiuPlatform.DataAccessor.DataAccessorBase.CreateConnectionString("192.168.0.40", "3306", "power21", "123qwe");
            dataAccessor = new MysqlDataAccessor(mysql_conn);
#else
            string influx_hostname = Environment.GetEnvironmentVariable(ENV_INFLUXDB_HOST);
            string influx_username = Environment.GetEnvironmentVariable(ENV_INFLUXDB_USERNAME);
            string influx_password = Environment.GetEnvironmentVariable(ENV_INFLUXDB_PASSWORD);

            dataAccessor = MysqlDataAccessor.CreateDataAccessFromEnvironment();
#endif
            influxDBClient = new InfluxDBClient(influx_hostname, influx_username, influx_password);
        }
示例#13
0
 /// <summary>
 /// Create logger
 /// </summary>
 /// <param name="logFactory"></param>
 /// <param name="fallbackCategory"></param>
 public NLogFactoryLocalizationLogger(NLog.LogFactory logFactory, string fallbackCategory = "Lexical.Localization")
 {
     this.logFactory     = logFactory ?? throw new ArgumentNullException(nameof(logFactory));
     this.fallbackLogger = logFactory.GetLogger(fallbackCategory);
 }
示例#14
0
 public ILogger GetLogger <T>()
 {
     return(new Logger(_nlogFactory.GetLogger(typeof(T).FullName)));
 }
示例#15
0
 public NLogLogger(Type typeToLog)
 {
     this.log = Factory.GetLogger(typeToLog.FullName);
 }