public void LogToTextFile_Success()
        {
            logger.Write(ex);
            var success = true;

            success.Should().BeTrue();
        }
Esempio n. 2
0
        public void Write(LogLevel level, Exception ex, string format, params object[] args)
        {
            if (Config.LoggerOptions.EnableConsoleLogger)
            {
                _consoleLogger.Write(level, ex, string.Format(format, args));
            }

            _textFileLogger.Write(level, ex, string.Format(format, args));
        }
Esempio n. 3
0
        public MerakiModule(TextFileLogger logger, SmartFlowContext context)
            : base("/meraki")
        {
            // Meraki will use this to validate we are the correct host
            Get["/"] = _ => Settings.Default.Validator;

            Post["/"] = _ =>
            {
                var req = this.Bind<MerakiDto>();

                // secret didnt match, return FORBIDDEN
                if (req.Secret != Settings.Default.Secret) return 403;

                // log to file (will log to database once its all working etc..)
                logger.Write(req.ToString(), Enums.LogLevel.Information);

                var floors = req.Data.ApFloors.Select(x => x.ToFloorEntity(req.Data.ApMac));

                foreach (var floor in floors)
                {
                    if (context.Floors.Any(x => x.ApMac == floor.ApMac && x.Name == floor.Name))
                    {
                        context.Floors.Attach(floor);
                    }
                    else
                    {
                        context.Floors.Add(floor);
                    }
                }

                var thisTime = DateTime.Now;
                var isDaylight = TimeZoneInfo.Local.IsDaylightSavingTime(thisTime);

                var observations = req.Data.Observations.Select(y => new Observation
                {
                    ApMac = req.Data.ApMac,
                    ClientMac = y.ClientMac,
                    Ipv4 = y.Ipv4,
                    Ipv6 = y.Ipv6,
                    Manufacturer = y.Manufacturer,
                    Os = y.Os,
                    Rssi = y.Rssi,
                    SeenTime = isDaylight ? y.SeenTime.AddHours(1) : y.SeenTime,
                    SeenEpoch = y.SeenEpoch,
                    Location = y.Location != null ? y.Location.ToLocationEntity(req.Data) : null
                });

                context.Observations.AddRange(observations);

                // return CREATED
                return 201;
            };
        }
Esempio n. 4
0
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

            var logger = new TextFileLogger(Settings.Default.FilePath, "Request", null, 30, "SmartFlow", "1")
            {
                MaximumLogSize = 15
            };

            container.Register(logger);
            container.Register<JsonSerializer, SmartFlowJsonSerializer>();

            logger.Write("Logging Configured", Enums.LogLevel.Information);
        }
Esempio n. 5
0
 public void LogInfoAndOpenFile()
 {
     logger.Write(Logger.MessageType.Info, "Test for logging info");
 }