Exemplo n.º 1
0
        private void WriteLogEntry(Logger.LogLevel level, object sender, string message, params object[] args)
        {
            try
            {
                // Ensure folder LOGS is created
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(this.Filename));
                if (!dir.Exists)
                {
                    dir.Create();
                }

                // Generate text for entry
                StringBuilder txt = new StringBuilder();
                txt.AppendLine(string.Format("{0} - {1} at {2}",
                                             DateTime.Now.ToString(Logger.FORMAT_DATETIME_LONG),
                                             level.ToString().ToUpper(),
                                             sender != null ? sender.GetType().Assembly.FullName : Application.ProductName));
                txt.AppendLine(string.Format(message, args));

                using (StreamWriter sw = File.AppendText(this.Filename))
                {
                    sw.WriteLine(txt.ToString());
                }

                // Set all used instances to null to minimize memory usage
                txt = null;
                dir = null;
            }
            catch
            {
                // This class can't thrown exceptions
                // Any exception is ignored
            }
        }
Exemplo n.º 2
0
        public void TestExcelExample1()
        {
            string pathExcel = Path.Combine(Environment.CurrentDirectory, "Data\\Example1.xlsx");
            string pathTemp  = TestLibrary.getTempFilename(".dbf");

            Xml_Form form  = generateForm();
            Excel    excel = new Excel();
            DBF      dbf   = new DBF(pathTemp, form.DBF);

            try
            {
                excel.OpenWorksheet(pathExcel);

                Work            work      = new Work(excel.worksheet, form, 120);
                Logger.LogLevel old_level = Logger.Level;
                Logger.SetLevel(Logger.LogLevel.TRACER);
                work.IterateRecords(dbf.appendRecord);
                Logger.SetLevel(old_level);
            }
            finally
            {
                dbf.close();
                excel.close();
            }
        }
 //This is a special case logger should be initialized before configuration class
 public static void InitLogLevel()
 {
     try
     {
         if (Environment.UserInteractive)
         {
             logLevel = Logger.LogLevel.DEBUG;
         }
         else
         {
             RegistryKey mydlpKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("MyDLP", true);
             //Get loglevel
             try
             {
                 logLevel = (Logger.LogLevel)mydlpKey.GetValue("log_level");
                 if (logLevel > Logger.LogLevel.DEBUG)
                 {
                     logLevel = Logger.LogLevel.DEBUG;
                 }
             }
             catch (Exception e)
             {
                 mydlpKey.SetValue("log_level", Logger.LogLevel.DEBUG, RegistryValueKind.DWord);
                 logLevel = Logger.LogLevel.INFO;
             }
         }
     }
     catch (Exception e)
     {
         Logger.GetInstance().Error("Unable to get registry key HKLM/Software/MyDLP "
                                    + e);
         logLevel = Logger.LogLevel.DEBUG;
     }
 }
Exemplo n.º 4
0
        private void WriteLogEntry(Logger.LogLevel level, object sender, string message, params object[] args)
        {
            try
            {
                // Generate text for entry
                StringBuilder txt = new StringBuilder();
                txt.AppendLine(string.Format(message, args));

                this.Log.WriteEntry(txt.ToString(), ConvertLogLevel(level));

                // Set all used instances to null to minimize memory usage
                txt = null;
            }
            catch
            {
                // try to write on an existing source on different Windows LOG file
                try
                {
                    this.Log.Log = string.Empty;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 5
0
        private static void LogEventLogCategories(string[] categories, Logger.LogLevel level)
        {
            //save a bit of CPU if the eventlog log has been silenced
            if (Logger.currentLogLevel < level)
            {
                return;
            }

            string result = "EventLogCategories[]: ";

            if (categories == null)
            {
                result += "null";
            }

            else if (categories.Length == 0)
            {
                result += " Count = 0 ";
            }

            else
            {
                int i = 0;
                foreach (string category in categories)
                {
                    result += String.Format("\n\t{0}: categoryID={1}", i, category);
                    i++;
                }
            }

            Logger.Log(result, level);
        }
Exemplo n.º 6
0
 public DebugMessage(Logger.LogLevel level, string senderName, string message)
 {
     Level      = level;
     Timestamp  = DateTimeOffset.UtcNow;
     SenderName = senderName;
     Text       = message;
 }
Exemplo n.º 7
0
        Color GetMessageColor(Logger.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case Logger.LogLevel.Fatal:
            case Logger.LogLevel.Error: {
                return(Color.red);
            }

            case Logger.LogLevel.Warn: {
                return(Color.yellow);
            }

            case Logger.LogLevel.Info: {
                return(Color.green);
            }

            case Logger.LogLevel.Debug: {
                return(Color.gray);
            }

            default: {
                return(Color.white);
            }
            }
        }
Exemplo n.º 8
0
        public static void Log(string msg, Logger.LogLevel level = Logger.LogLevel.NONE)
        {
            string prefix = "[jkAnti] ";

            switch (level)
            {
            case LogLevel.ERROR:
                Debug.WriteLine(prefix + "^1[ERROR] " + msg + "^0");
                break;

            case LogLevel.BLUE:
                Debug.WriteLine("^5" + msg + "^0");
                break;

            case LogLevel.INFO:
                Debug.WriteLine(prefix + "^5[INFO] " + msg + "^0");
                break;

            case LogLevel.NONE:
                Console.WriteLine(msg);
                break;

            case LogLevel.DEBUG:
                if (ConfigManager.Config.DebugMode == true)
                {
                    Debug.WriteLine(prefix + "[DEBUG] " + msg);
                }
                break;

            case LogLevel.WARNING:
                Debug.WriteLine(prefix + "^8[WARNING] " + msg + "^0");
                break;
            }
        }
Exemplo n.º 9
0
 internal static void ExecuteCallback(Logger.LogLevel level, string message, bool containsPii)
 {
     lock (LockObj)
     {
         _logCallback?.Invoke(level, message, containsPii);
     }
 }
Exemplo n.º 10
0
        private static void LogSecuritySwitchAction(string message, Logger.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case SecuritySwitch.Logger.LogLevel.Debug:
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug(message);
                }
                break;

            case SecuritySwitch.Logger.LogLevel.Info:
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info(message);
                }
                break;

            case SecuritySwitch.Logger.LogLevel.Warn:
                if (Logger.IsWarnEnabled)
                {
                    Logger.Warn(message);
                }
                break;
            }
        }
Exemplo n.º 11
0
 public void Log(Logger.LogLevel level, string message, bool containsPii)
 {
     if (!containsPii)
     {
         string requestId = Activity.Current?.Id;
         log.AppendLine($"{requestId} - {level.ToString()} - {message}");
     }
 }
Exemplo n.º 12
0
        static void ParseArgs(string[] args)
        {
            foreach (var arg in args)
            {
                if (!arg.Contains('=', StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                var splitArg = arg.Split('=');
                if (splitArg.Length != 2)
                {
                    continue;
                }

                switch (splitArg[0])
                {
                case "-t":
                case "--tibiadirectory":
                {
                    _tibiaDirectory = splitArg[1].Replace("\"", "");
                }
                break;

                case "-p":
                case "--port":
                {
                    if (int.TryParse(splitArg[1], out var port))
                    {
                        _httpPort = port;
                    }
                }
                break;

                case "-l":
                case "--login":
                {
                    _loginWebService = splitArg[1];
                }
                break;

                case "--loglevel":
                {
                    _logLevel = Logger.ConvertToLogLevel(splitArg[1]);
                }
                break;

                case "--logoutput":
                {
                    _logOutput = Logger.ConvertToLogOutput(splitArg[1]);
                }
                break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 13
0
        public Assert(bool condition, string message, Logger.LogLevel logLevel)
        {
            if (!condition)
            {
                Logger.GetOrCreate("BrUtility").Log(logLevel, "Assert failed: " + message);
            }

            this.condition = condition;
        }
Exemplo n.º 14
0
        private void CmdAccept_Click(object sender, EventArgs e)
        {
            if (cboSkin.SelectedItem == null)
            {
                MessageBox.Show("You must select the visual skin.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                cboSkin.Focus();
                return;
            }

            // Change the current skin
            SkinContainer skin = ((ImageComboBoxItem)cboSkin.SelectedItem).Value as SkinContainer;

            SkinManager.EnableFormSkins();
            DevExpress.LookAndFeel.UserLookAndFeel.Default.Style    = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = skin.SkinName;

            // General settings
            StudioContext.SkinName        = skin.SkinName;
            StudioContext.OpenLastProject = chkProjectsLoadLast.Checked;

            // LOGs settings
            Logger.LogLevel level = this.GetLoggerLevel(cboLogFileLevel);
            if (level == Logger.LogLevel.Disabled)
            {
                Logger.ModuleManager.RemoveLibrary(typeof(FileLogger).Name);
            }
            else
            {
                XmlSettingsItem library = new XmlSettingsItem(typeof(FileLogger).Name, typeof(FileLogger).FullName);
                library.AddSetting(Logger.SETTING_LOG_LEVEL, level.ToString().ToLower());
                Logger.ModuleManager.AddLibrary(library);
            }

            level = this.GetLoggerLevel(cboLogWindowsLevel);
            if (level == Logger.LogLevel.Disabled)
            {
                Logger.ModuleManager.RemoveLibrary(typeof(WinLogger).Name);
            }
            else
            {
                XmlSettingsItem library = new XmlSettingsItem(typeof(WinLogger).Name, typeof(WinLogger).FullName);
                library.AddSetting(Logger.SETTING_LOG_LEVEL, level.ToString().ToLower());
                library.AddSetting(WinLogger.SETTING_LOG_NAME, txtLogWindowsName.Text);
                library.AddSetting(WinLogger.SETTING_LOG_SOURCE, txtLogWindowsSource.Text);
                Logger.ModuleManager.AddLibrary(library);
            }

            OTCContext.Settings.SaveSettings();

            this.RefreshPluginsBar = this.PluginsControl.PluginsChanged;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 15
0
        public static LogType GetLogType(this Logger.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case Logger.LogLevel.Fatal:
            case Logger.LogLevel.Error:  return(LogType.Error);

            case Logger.LogLevel.Warn: return(LogType.Warning);

            default: return(LogType.Log);
            }
        }
Exemplo n.º 16
0
        public void reportSchemaCache(Logger.LogLevel logLevel)
        {
            if (logLevel > Logger.currentLogLevel)
            {
                return;
            }

            foreach (KeyValuePair <string, SchemaType> entry in _attrTypeLookup)
            {
                string            key        = entry.Key as string;
                LdapAttributeType schemaType = entry.Value as LdapAttributeType;
                if (schemaType != null)
                {
                    Logger.Log("Attribute Key = " + key, logLevel);
                    Logger.Log("    SchemaType::CName      = " + schemaType.CName, logLevel);
                    Logger.Log("              ::AttrSyntax = " + schemaType.AttributeSyntax, logLevel);
                    Logger.Log("              ::DataTypa   = " + schemaType.DataType, logLevel);
                    Logger.Log("              ::AttributeDisplayName   = " + schemaType.AttributeDisplayName, logLevel);
                }
            }
            foreach (KeyValuePair <string, SchemaType> entry in _classTypeLookup)
            {
                string        key        = entry.Key as string;
                LdapClassType schemaType = entry.Value as LdapClassType;
                if (schemaType != null)
                {
                    Logger.Log("Class Key = " + key, logLevel);
                    Logger.Log("    SchemaType::CName      = " + schemaType.CName, logLevel);
                    Logger.Log("              ::AttrSyntax = " + schemaType.AttributeSyntax, logLevel);
                    Logger.Log("              ::DataTypa   = " + schemaType.DataType, logLevel);
                    Logger.Log("              ::AttributeDisplayName   = " + schemaType.AttributeDisplayName, logLevel);
                }
            }

            foreach (KeyValuePair <string, SchemaType> entry in _dnTypeLookup)
            {
                string     key        = entry.Key as string;
                SchemaType schemaType = entry.Value as SchemaType;
                if (schemaType != null)
                {
                    Logger.Log("Display Name Key = " + key, logLevel);
                    Logger.Log("    SchemaType::CName      = " + schemaType.CName, logLevel);
                    Logger.Log("              ::AttrSyntax = " + schemaType.AttributeSyntax, logLevel);
                    Logger.Log("              ::DataTypa   = " + schemaType.DataType, logLevel);
                    Logger.Log("              ::AttributeDisplayName   = " + schemaType.AttributeDisplayName, logLevel);
                }
            }
        }
Exemplo n.º 17
0
        private EventLogEntryType ConvertLogLevel(Logger.LogLevel level)
        {
            switch (level)
            {
            case Logger.LogLevel.Info:
                return(EventLogEntryType.Information);

            case Logger.LogLevel.Warn:
                return(EventLogEntryType.Warning);

            case Logger.LogLevel.Debug:
                return(EventLogEntryType.SuccessAudit);

            default:
                return(EventLogEntryType.Error);
            }
        }
Exemplo n.º 18
0
        private void RemoveLogFilter(Logger.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case Logger.LogLevel.INFO:
                m_logInfoEnable = false;
                break;

            case Logger.LogLevel.WARNING:
                m_logWaringEnable = false;
                break;

            case Logger.LogLevel.ERROR:
                m_logErrorEnable = false;
                break;
            }
            RefreshView();
        }
Exemplo n.º 19
0
        private static void GetLoggerSetting(out bool isEnabled, out Logger.LogLevel logSwitch)
        {
            string isEnabledString = ConfigurationManager.AppSettings["Log"];
            string logSwitchString = ConfigurationManager.AppSettings["LogSwitch"];

            isEnabled = true;
            if (String.Compare(isEnabledString, "Enabled", true) != 0)
            {
                isEnabled = false;
            }
            logSwitch = Logger.LogLevel.All;
            int temp;

            if (!int.TryParse(logSwitchString, out temp))
            {
                temp = (int)Logger.LogLevel.All;
            }
            logSwitch = (Logger.LogLevel)temp;
        }
Exemplo n.º 20
0
 private void WriteLineImpl(Logger.LogLevel level, string logText)
 {
     if (level == Logger.LogLevel.Error)
     {
         logText = "* " + logText;
     }
     else
     {
         logText = "  " + logText;
     }
     // Write the string to a file.
     lock (_locker)
     {
         using (StreamWriter file = new StreamWriter(_filepath, append: true))
         {
             file.WriteLine("{0:yyyy-MM-dd HH:mm:ss}: {1}", DateTime.UtcNow, logText);
         }
     }
 }
Exemplo n.º 21
0
        private void AddLogFilter(Logger.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case Logger.LogLevel.INFO:
                m_logInfoEnable = true;
                break;

            case Logger.LogLevel.WARNING:
                m_logWaringEnable = true;
                break;

            case Logger.LogLevel.ERROR:
                m_logErrorEnable = true;
                break;
            }
            Debug.Log("logLevel: " + logLevel);
            RefreshView();
        }
Exemplo n.º 22
0
        public void SetUp()
        {
            _oldLevel           = Logger.LoggingLevel;
            Logger.LoggingLevel = Logger.LogLevel.Verbose;

            Logger.Log("Started testing");

            _testGraph = new Graph <Point>(PointCalculator.This);
            _testGraph.Add(new Point(0, 1));
            _testGraph.AddConnection(new Point(0, 1), new Point(1, 2));
            _testGraph.AddConnection(new Point(2, 3), new Point(3, 4));
            _testGraph.AddConnection(new Point(3, 4), new Point(1, 2));
            // separate net
            _testGraph.AddConnection(new Point(800, 100), new Point(900, 100));
            _testGraph.AddConnection(new Point(900, 100), new Point(850, 1000));
            _testGraph.AddConnection(new Point(800, 100), new Point(850, 1000));
            _testGraph.AddConnection(new Point(850, 1000), new Point(950, 800));
            _testGraph.AddConnection(new Point(950, 800), new Point(20, 80));
            _testGraph.AddConnection(new Point(950, 800), new Point(800, 100));
        }
Exemplo n.º 23
0
        public static void verifyFileExists(string path, Logger.LogLevel level)
        {
            FileInfo fi = new FileInfo(path);

            string status = "";

            if (fi != null && fi.Exists && fi.Length > 0)
            {
                status = "OK";
            }
            else
            {
                Logger.ShowUserError(String.Format("Warning: File Not Found: {0}", path));
                status = "MISSING";
            }

            Logger.Log(
                String.Format("Checking {0} ...... {1}", path, status),
                Logger.manageLogLevel);
        }
Exemplo n.º 24
0
        public static void LogMessage(Logger.LogLevel logLevel, string formattedMessage)
        {
            switch (logLevel)
            {
            case Logger.LogLevel.Error:
                PlatformLogger.Error(formattedMessage);
                break;

            case Logger.LogLevel.Warning:
                PlatformLogger.Warning(formattedMessage);
                break;

            case Logger.LogLevel.Info:
                PlatformLogger.Information(formattedMessage);
                break;

            case Logger.LogLevel.Verbose:
                PlatformLogger.Verbose(formattedMessage);
                break;
            }
        }
Exemplo n.º 25
0
        public void LogDelegate(Logger.LogLevel level, string message, bool containsPii)
        {
            Action action = null;

            if (containsPii)
            {
                action = () =>
                {
                    msalPIILogsTextBox.AppendText(message + Environment.NewLine);
                };
            }
            else
            {
                action = () =>
                {
                    msalLogsTextBox.AppendText(message + Environment.NewLine);
                };
            }

            this.BeginInvoke(new MethodInvoker(action));
        }
Exemplo n.º 26
0
        private static void LogEventLogRecords(EventLogRecord[] records, Logger.LogLevel level)
        {
            //save a bit of CPU if the eventlog log has been silenced
            if (Logger.currentLogLevel < level)
            {
                return;
            }

            string result = "EventLogRecords[]: ";

            if (records == null)
            {
                result += "null";
            }

            else if (records.Length == 0)
            {
                result += " Count=0";
            }

            else
            {
                int i = 0;

                foreach (EventLogRecord record in records)
                {
                    result += String.Format("\n\t{0}: recordID={1}, eventID={2}, eventType={3}, eventTime={4}",
                                            i, record.dwEventRecordId, record.pszEventType, record.dwEventDateTime, record.pszEventCategory);
                    result += String.Format("\n\t\tsource: {0}, user: {1}, computer: {2}",
                                            record.pszEventSource, record.pszUser, record.pszComputer);
                    result += String.Format("\n\t\tdescription: {0}", record.pszDescription);
                    result += String.Format("\n\t\tdata: {0}", record.pszData);

                    i++;
                }
            }

            Logger.Log(result, level);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Check if an entry level must be logged using the current log level.
        /// </summary>
        /// <param name="entryLevel"></param>
        /// <param name="logCurrentLevel"></param>
        /// <returns></returns>
        public static bool IsLoggableEntry(Logger.LogLevel entryLevel, Logger.LogLevel logCurrentLevel)
        {
            if (entryLevel == LogLevel.Critical)
            {
                return(true);
            }

            switch (logCurrentLevel)
            {
            case LogLevel.Debug:
                return(true);

            case LogLevel.Info:
                return(entryLevel == LogLevel.Info || entryLevel == LogLevel.Warn || entryLevel == LogLevel.Error);

            case LogLevel.Warn:
                return(entryLevel == LogLevel.Warn || entryLevel == LogLevel.Error);

            case LogLevel.Error:
                return(entryLevel == LogLevel.Error);
            }

            return(false);
        }
Exemplo n.º 28
0
        static bool ParseArgs(string[] args)
        {
            foreach (var arg in args)
            {
                var splitArg = arg.Split('=');
                if (splitArg.Length == 1)
                {
                    switch (splitArg[0])
                    {
                    case "--items":
                    {
                        _extractItemData = true;
                    }
                    break;

                    case "--lookitemtext":
                    {
                        _extractLookItemText = true;
                    }
                    break;

                    case "--map":
                    {
                        _extractMapData = true;
                    }
                    break;

                    case "--monsters":
                    {
                        _extractMonsterData = true;
                    }
                    break;

                    case "--npcs":
                    {
                        _extractNpcData = true;
                    }
                    break;

                    case "-h":
                    case "--help":
                    {
                        Console.WriteLine("[required] -r=<path>, --recording=<path>, or --recordings=<path>: " +
                                          "<path> can either be a recording file or directory of recording files.\n");
                        Console.WriteLine("[optional] -o=<path> or --outdirectory=<path>:" +
                                          "<path> is the directory you want the OTBM file to be written to. " +
                                          "If the directory does not exist, it will be created. " +
                                          "If not supplied, the OTBM file will be written to the current directory.\n");
                        Console.WriteLine("[optional] -t=<path> or --tibiadirectory=<path>: " +
                                          "<path> is the package directory of the Tibia client to target. " +
                                          "If this parameter is not specified, and an OXR file is being used, " +
                                          "the Extract app will first try to find the equivalent client version in the ClientData folder. " +
                                          "Otherwise, it will use the default path CipSoft uses upon installation.\n");
                        Console.WriteLine("[optional] --time=<seconds> or --timestamp=<seconds>: " +
                                          "<seconds> is the number of seconds from the start of the recording to stop extraction." +
                                          "If this is not specified, extraction will run until the end of the recording.");
                        Console.WriteLine("[optional] --otb=<path>: " +
                                          "<path> is the path to your items.otb file. +" +
                                          "By default, the OTBM file is created using client IDs for items. +" +
                                          "By specifying an OTB file, the OTBM file will be created with server IDs.");

                        Console.WriteLine("[optional] --loglevel=[debug,info,warning,error,disabled]: " +
                                          "Sets the log level within the API. Default: error");
                        Console.WriteLine("[optional] --logoutput=[console,file]: " +
                                          "Sets the preferred output for logging from the API. " +
                                          "file log is in the format: day_month_year__hour_minute_second.log. Default: console");

                        Console.WriteLine("The following options can be combined to extract multiple data sets at once, or individually, " +
                                          "but at least one option must be specified or the extraction process won't proceed.\n");
                        Console.WriteLine("--items: Used for extracting item information to items.txt.\n");
                        Console.WriteLine("--lookitemtext: Used for extracting text from `Look` messages for items to lookitemtext.txt.\n");
                        Console.WriteLine("--map: Used for extracting map data to the OTBM format.\n");
                        Console.WriteLine("--monsters: Used for extracting monster information to monsters.txt.\n");
                        Console.WriteLine("--npcs: Used for extracting npc information to npcs.txt.\n");
                    }
                        return(false);

                    default:
                        break;
                    }
                }
                else if (splitArg.Length == 2)
                {
                    switch (splitArg[0])
                    {
                    case "-r":
                    case "--recording":
                    case "--recordings":
                    {
                        _recording = splitArg[1].Replace("\"", "");
                    }
                    break;

                    case "-o":
                    case "--outdirectory":
                    {
                        _outDirectory = splitArg[1].Replace("\"", "");
                    }
                    break;

                    case "-t":
                    case "--tibiadirectory":
                    {
                        _tibiaDirectory = splitArg[1].Replace("\"", "");
                    }
                    break;

                    case "--time":
                    case "--timestamp":
                    {
                        if (!ulong.TryParse(splitArg[1], out _timestamp))
                        {
                            Console.WriteLine($"{splitArg[1]} is not a valid timestamp!");
                            return(false);
                        }
                    }
                    break;

                    case "--otb":
                    {
                        _otbFilename = splitArg[1].Replace("\"", "");
                    }
                    break;

                    case "--loglevel":
                    {
                        _logLevel = Logger.ConvertToLogLevel(splitArg[1]);
                    }
                    break;

                    case "--logoutput":
                    {
                        _logOutput = Logger.ConvertToLogOutput(splitArg[1]);
                    }
                    break;

                    default:
                        break;
                    }
                }
            }
            return(true);
        }
        public static bool GetUserConf()
        {
            Logger.GetInstance().Debug("GetUserConf called");

            try
            {
                RegistryKey mydlpKey = Registry.LocalMachine.OpenSubKey("Software", true).CreateSubKey("MyDLP");
                //Get screenShotConfiguration
                if ((int)(getRegistryConfSafe(mydlpKey, "prtscr_block", 0, RegistryValueKind.DWord)) == 0)
                {
                    blockScreenShot = false;
                }
                else
                {
                    blockScreenShot = true;
                    screentShotProcesses = (String)getRegistryConfSafe(mydlpKey, "prtscr_processes", 0, RegistryValueKind.String);
                }
                //Get archiveInbound
                if ((int)(getRegistryConfSafe(mydlpKey, "archive_inbound", 0, RegistryValueKind.DWord)) == 0)
                {
                    archiveInbound = false;
                }
                else
                {
                    archiveInbound = true;
                }
                //Get usbSerialAccessControl
                if ((int)(getRegistryConfSafe(mydlpKey, "usb_serial_access_control", 0, RegistryValueKind.DWord)) == 0)
                {
                    usbSerialAccessControl = false;
                }
                else
                {
                    usbSerialAccessControl = true;
                }
                //Get printMonitor
                if ((int)(getRegistryConfSafe(mydlpKey, "print_monitor", 0, RegistryValueKind.DWord)) == 0)
                {
                    printerMonitor = false;
                }
                else
                {
                    printerMonitor = true;
                }
                //Get printerPrefix
                printerPrefix = (String)getRegistryConfSafe(mydlpKey, "printer_prefix", "(MyDLP)", RegistryValueKind.String);

                //Get remStorEncryption
                if ((int)(getRegistryConfSafe(mydlpKey, "usbstor_encryption", 0, RegistryValueKind.DWord)) == 0)
                {
                    remStorEncryption = false;
                }
                else
                {
                    remStorEncryption = true;
                }

                //Get seapServer
                seapServer = (String)getRegistryConfSafe(mydlpKey, "seap_server", "127.0.0.1", RegistryValueKind.String);
                //Get managementServer
                managementServer = (String)getRegistryConfSafe(mydlpKey, "management_server", "127.0.0.1", RegistryValueKind.String);
                //Get seapPort
                seapPort = (int)getRegistryConfSafe(mydlpKey, "seap_port", 9099, RegistryValueKind.DWord);

                //Try to use old management server if local host found for management server
                if (managementServer == "127.0.0.1")
                {
                    managementServer = (String)getRegistryConfSafe(mydlpKey, "ManagementServer", "127.0.0.1", RegistryValueKind.String, false);
                    //set new key
                    mydlpKey.SetValue("management_server", managementServer, RegistryValueKind.String);
                }
                //try to delete old key anyway
                mydlpKey.DeleteValue("ManagementServer", false);
                //Get logLimit
                logLimit = (int)getRegistryConfSafe(mydlpKey, "log_limit", 10485760, RegistryValueKind.DWord);
                //Get maximumObjectSize
                maximumObjectSize = (int)getRegistryConfSafe(mydlpKey, "maximum_object_size", 10485760, RegistryValueKind.DWord);
                if (!Environment.UserInteractive)
                {
                    //Get loglevel
                    logLevel = (Logger.LogLevel)getRegistryConfSafe(mydlpKey, "log_level", 1, RegistryValueKind.DWord);
                    if (logLevel > Logger.LogLevel.DEBUG) logLevel = Logger.LogLevel.DEBUG;
                }
            }
            catch (Exception e)
            {
                Logger.GetInstance().Error("Unable to open registry key HKLM/Software/MyDLP "
                    + e);
                return false;
            }
            Logger.GetInstance().Info("MyDLP LogLevel: " + logLevel.ToString());
            Logger.GetInstance().Info("MyDLP ManagementServer: " + managementServer);
            Logger.GetInstance().Info("MyDLP ArchiveInbound: " + archiveInbound);
            Logger.GetInstance().Info("MyDLP USBSerialAccessControl: " + usbSerialAccessControl);
            Logger.GetInstance().Info("MyDLP PrinterMonitor: " + printerMonitor);
            Logger.GetInstance().Info("MyDLP LogLimit: " + logLimit);
            Logger.GetInstance().Info("MyDLP MaximumObjectSize: " + maximumObjectSize);
            Logger.GetInstance().Info("MyDLP PrinterPrefix: " + printerPrefix);
            return true;
        }
 //This is a special case logger should be initialized before configuration class
 public static void InitLogLevel()
 {
     try
     {
         if (Environment.UserInteractive)
         {
             logLevel = Logger.LogLevel.DEBUG;
         }
         else
         {
             RegistryKey mydlpKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("MyDLP", true);
             //Get loglevel
             try
             {
                 logLevel = (Logger.LogLevel)mydlpKey.GetValue("log_level");
                 if (logLevel > Logger.LogLevel.DEBUG) logLevel = Logger.LogLevel.DEBUG;
             }
             catch (Exception e)
             {
                 mydlpKey.SetValue("log_level", Logger.LogLevel.DEBUG, RegistryValueKind.DWord);
                 logLevel = Logger.LogLevel.INFO;
             }
         }
     }
     catch (Exception e)
     {
         Logger.GetInstance().Error("Unable to get registry key HKLM/Software/MyDLP "
              + e);
         logLevel = Logger.LogLevel.DEBUG;
     }
 }
Exemplo n.º 31
0
 public static void LogMessage(Logger.LogLevel level, string message, IntPtr data)
 {
     Console.WriteLine($"NFluidsynthAndroidLogger ({level}): {message}");
 }
Exemplo n.º 32
0
 public static void AssertNotNull(object obj, string message, Logger.LogLevel logLevel)
 {
     new Assert(obj != null, message, logLevel);
 }