static LogManager() { _logger = new NCacheLogger(); _logger.Initialize(LoggerNames.MemcacheGateway); string loggingLevel = System.Configuration.ConfigurationManager.AppSettings["LoggingLevel"]; if (!string.IsNullOrEmpty(loggingLevel)) { _logger.SetLevel(loggingLevel); } else { _logger.SetLevel("Info"); } }
/// <summary> /// Writes an error, warning, information, success audit, or failure audit /// entry with the given message text to the event log. /// </summary> /// <param name="msg">The string to write to the event log.</param> /// <param name="type">One of the <c>EventLogEntryType</c> values.</param> public static void LogEvent(string source, string msg, EventLogEntryType type, short category, int eventId) { try { OSInfo currentOS = OSInfo.Windows; #if NETCORE if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { currentOS = OSInfo.Linux; } #endif if (currentOS == OSInfo.Windows) { try { int level = (int)type; if ((level & s_logLevel) == level) { using (EventLog ncLog = new EventLog("Application")) { ncLog.Source = source; ncLog.WriteEntry(msg, type, eventId); } } } catch (Exception) { } } else // For Linux { if (_nCacheEventLogger == null) { _nCacheEventLogger = new NCacheLogger(); _nCacheEventLogger.InitializeEventsLogging(); } _nCacheEventLogger.EventLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss, fff"), source, eventId.ToString(), type.ToString(), msg); } } catch { } }
internal EventManager(string cacheName, NCacheLogger logger, Cache cache) { _cacheName = cacheName; _logger = logger; _cache = cache; }
protected internal void Configure(LogLevel logLevel, string path) { if (!isConfigured) { this.logLevel = logLevel; if (path != null) { if (File.Exists(path)) { throw new Exception("The specified location for logging is not a directory but a path to a file."); } if (!Directory.Exists(path)) { throw new Exception("The directory specified for logging does not exist."); } this.path = path; } #if JAVA this.path = Path.Combine(this.path, @"log"); #else this.path = Path.Combine(this.path, @"log-files"); #endif this.path = Path.Combine(this.path, @"EFCoreLogs"); if (!Directory.Exists(this.path)) { Directory.CreateDirectory(this.path); } IDictionary properties = new Dictionary <string, string> { ["log-path"] = this.path }; nCacheLogger = new NCacheLogger(); nCacheLogger.Initialize(properties, NCacheConfiguration.CacheId, "EFCoreLogs"); string logLevelLog4Net = default(string); switch (logLevel) { case LogLevel.Trace: logLevelLog4Net = LoggerLevel.All; break; case LogLevel.Debug: logLevelLog4Net = LoggerLevel.Debug; break; case LogLevel.Information: logLevelLog4Net = LoggerLevel.Info; break; case LogLevel.Warning: logLevelLog4Net = LoggerLevel.Warn; break; case LogLevel.Error: logLevelLog4Net = LoggerLevel.Error; break; case LogLevel.Critical: logLevelLog4Net = LoggerLevel.CriticalInfo; break; case LogLevel.None: logLevelLog4Net = LoggerLevel.Off; break; } if (string.IsNullOrEmpty(logLevelLog4Net)) { logLevelLog4Net = LoggerLevel.Off; } nCacheLogger.SetLevel(logLevelLog4Net); isConfigured = true; } }