コード例 #1
0
        public Tnxlog()
        {
#if DEBUG || LOG
            var loggingConfig = new NLog.Config.LoggingConfiguration();
#endif
            dataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tnxlog");
#if DEBUG
            dataPath = Path.Combine(dataPath, "debug");
            var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
            loggingConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
#endif
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
#if LOG
            logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName        = Path.Combine(dataPath, "debug.log"),
                Layout          = "${longdate} ${level} ${message}  ${exception:format=toString,Data:maxInnerExceptionLevel=10} ${stacktrace:format=DetailedFlat:topFrames=10}",
                ArchiveEvery    = NLog.Targets.FileArchivePeriod.Sunday,
                Encoding        = Encoding.UTF8,
                MaxArchiveFiles = 1
            };
            loggingConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
#endif
#if DEBUG || LOG
            NLog.LogManager.Configuration = loggingConfig;
#endif
#if LOG
            Logger.Info("Start");
#endif
            qsoFilePath = Path.Combine(dataPath, "qso.dat");
            config      = XmlConfig.create <TnxlogConfig>(Path.Combine(dataPath, "config.xml"));
            for (int field = 0; field < TnxlogConfig.QthFieldCount; field++)
            {
                qthFields[field] = config.getQthFieldValue(field);
            }
            _loc                           = config.loc;
            httpService                    = new HttpService(config.httpService, this);
            transceiverController          = new TransceiverController(config.transceiverController);
            adifLogWatcher.OnNewAdifEntry += newAdifLogEntry;
            qsoFactory                     = new QSOFactory(this);
            qsoList                        = QSOFactory.ReadList <BindingList <QSO> >(qsoFilePath);
            if (qsoList == null)
            {
                qsoList       = new BindingList <QSO>();
                qsoFactory.no = 1;
            }
            else if (qsoList.Count > 0)
            {
                qsoFactory.no = qsoList.First().no + 1;
            }
            qsoList.ListChanged += QsoList_ListChanged;
            _formMain            = new FormMain(config.formMain, this);
            if (config.autoLogin)
            {
                Task.Run(async() => await httpService.login(true));
            }
            initServices();
        }