void LogHandler(string Msg, LogLevel logLevel) { Console.WriteLine(Msg); _logger.Log(logLevel, 20, Msg); }
public static bool IssueContainsRelevantLabels(Issue issue, string issueLabel, string repoLabel, ILogger log = null, Microsoft.Extensions.Logging.LogLevel logLevel = Microsoft.Extensions.Logging.LogLevel.Information) { if (issue == null) { WriteWarning("A null issue was passed.", log); return(false); } WriteTrace($"Issue {issue.Number} has labels {string.Join(", ", issue.Labels.Select(l => $"'{l.Name}'"))}", log, logLevel); bool isIssueLabel = false; if (issueLabel == GithubLabelNames.IssueLabel) { isIssueLabel = issue.Labels.Any(l => l.Name == repoLabel) && !issue.Labels.Any(l => l.Name == GithubLabelNames.HotfixLabel || l.Name == GithubLabelNames.RollbackLabel || l.Name == GithubLabelNames.DowntimeLabel || l.Name == GithubLabelNames.FailureLabel); } else { isIssueLabel = issue.Labels.Any(l => l.Name == issueLabel) && issue.Labels.Any(l => l.Name == repoLabel); } if (isIssueLabel) { WriteDebug($"Issue {issue.Number} determined to be {issueLabel} for {repoLabel}", log, logLevel); } return(isIssueLabel); }
/// <inheritdoc/> public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { return(logger.IsEnabled(logLevel)); }
public void Log <TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { configuration.LogSafe(Convert(logLevel), formatter(state, exception)); }
/// <inheritdoc/> public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { return(IsLogLevelEnabled(ToNeonLevel(logLevel))); }
/// <inheritdoc /> public bool IsEnabled(LogLevel logLevel) { return(logLevel != LogLevel.None); }
public void Log <TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } if (formatter == null) { throw new ArgumentNullException(nameof(formatter)); } var logBuilder = new StringBuilder(); var message = formatter(state, exception); if (string.IsNullOrEmpty(message) && exception != null) { message = exception.Message; } SystemLog createEntity = new SystemLog() { Message = CoreUtility.TruncateString(message, 512) ?? "Empty", FullMessage = CreateFullMessage(logLevel, eventId, message, exception) ?? "Empty", Level = logLevel }; if (_contextAccessor?.HttpContext != null) { createEntity.IpAddress = _contextAccessor.HttpContext.GetCurrentIpAddress(); createEntity.PageUrl = _contextAccessor.HttpContext.GetThisPageUrl(); createEntity.ReferrerUrl = _contextAccessor.HttpContext.GetUrlReferrer(); createEntity.UserAgent = _contextAccessor.HttpContext.Request?.Headers["User-Agent"]; } _logtaskQueue.QueueBackgroundWorkItem(async token => { Uri[] listNodes = _elasticLogOptions.Nodes.Split(";").Select(q => new Uri(q)).ToArray(); StaticConnectionPool pool = new StaticConnectionPool(listNodes); ConnectionSettings settings = new ConnectionSettings(pool); settings.DefaultIndex($"log-{DateTime.Now.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture)}"); await(new ElasticClient(settings)).IndexDocumentAsync(createEntity); }); string CreateFullMessage(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, string message, Exception exception) { var logBuilder = new StringBuilder(); var logLevelString = logLevel.ToString(); logBuilder.Append($"{DateTime.Now.ToString(new System.Globalization.CultureInfo("vi-VN"))} - {logLevelString} - {_name}"); if (null != eventId && eventId.Id > 0) { logBuilder.Append($" [ {eventId.Id} - {eventId.Name ?? "null"} ] "); } AppendAndReplaceNewLine(logBuilder, message); if (exception != null) { logBuilder.Append(' '); AppendAndReplaceNewLine(logBuilder, exception.ToString()); } return(logBuilder.ToString());
/// <summary> /// Determines whether the logging level is enabled. /// </summary> /// <param name="logLevel">The log level.</param> /// <returns>The <see cref="bool"/> value indicating whether the logging level is enabled.</returns> /// <exception cref="ArgumentOutOfRangeException">Throws when <paramref name="logLevel"/> is outside allowed range</exception> public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) => log.IsEnabled(type, (Umbraco.Core.Logging.LogLevel)logLevel);
/// <summary> /// 是否启用 /// </summary> /// <param name="logLevel">日志级别</param> /// <returns></returns> public bool IsEnabled(LogLevel logLevel) { return(true); }
public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { return(this.fullTracing || this.logger.IsEnabled(logLevel)); }
private void Log(Microsoft.Extensions.Logging.LogLevel level, string message, [CallerMemberName] string memberName = default) { _logger?.Log(level, $"{nameof(ManagedIdentityTokenProvider)}.{memberName} :: {message}"); }
private bool IsEnabledFor(MicrosoftLogLevel logLevel) { return(logger.IsEnabled(logLevel)); }
public bool IsEnabled(MSLogLevel logLevel) { var nlog = LogLevelMap[logLevel]; return(_nlog.IsEnabled(nlog)); }
/// <inheritdoc /> public bool IsEnabled(LogLevel logLevel) { return(IsEnabled(logLevel.ToNLogLevel())); }
public static MultilineLogEntry StartMultiline(Microsoft.Extensions.Logging.LogLevel level = Microsoft.Extensions.Logging.LogLevel.Information, Exception exception = null) { return(new MultilineLogEntry(_Logger.Value, level, exception)); }
/// <summary> /// Checks if the given <paramref name="logLevel" /> is enabled. /// </summary> /// <param name="logLevel">level to be checked.</param> /// <returns> /// <c>true</c> if enabled. /// </returns> public virtual bool IsEnabled(mslogging.LogLevel logLevel) { return(_rollbarOptions.Filter(_name, logLevel)); }
/// <summary> /// 是否启用 /// </summary> /// <param name="logLevel">日志级别</param> public bool IsEnabled(LogLevel logLevel) => true;
/// <inheritdoc /> public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) => true; // Verbosity is handled by the inner logger
public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { return(!_elasticLogOptions.FilterLogLevels.Contains(logLevel)); }
public void Log <TState>(Microsoft.Extensions.Logging.LogLevel logLevel, Microsoft.Extensions.Logging.EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) where TState : LogEntryParameters { _logger.Log(logLevel, eventId, state, exception, formatter); }
/// <summary> /// Configures logging for Entity framework core provider. Helpful for debugging and getting detailed information in case /// of any errors/exceptions. /// By default the Logs are created in NCache's log directory unless specified. /// </summary> /// <param name="factory">The custom logger factory that will provide the loggers.</param> /// <param name="categoryName">specifies the category name of the logger.</param> /// <param name="path">corresponds to the custom path where user wants to create the logs. can be null.</param> /// <param name="logLevel">Specifies the severity of the event that is to be logged.</param> public static void ConfigureLogger(ILoggerFactory factory = default(ILoggerFactory), string categoryName = default(string), string path = default(string), Microsoft.Extensions.Logging.LogLevel logLevel = Microsoft.Extensions.Logging.LogLevel.Debug) { if (factory == default(ILoggerFactory)) { factory = EFLoggerFactory.Instance; } _loggerFactory = factory; ILogger logger = factory.CreateLogger(categoryName ?? ""); if (factory is EFLoggerFactory) { ((EFLogger)logger).Configure(logLevel, path); QueryCacheManager.Loggers = new ILogger[] { logger }; } else { FieldInfo loggersField = logger.GetType().GetField("_loggers", BindingFlags.NonPublic | BindingFlags.Instance); QueryCacheManager.Loggers = (ILogger[])loggersField.GetValue(logger); } }
bool ILogger.IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { return(false); }
/// <inheritdoc/> public void Log <TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception e, Func <TState, Exception, string> formatter) { // It appears that formatters are not supposed to generate anything for // exceptions, so we don't have to do anything special. // // https://github.com/aspnet/Logging/issues/442 var message = formatter(state, null) ?? string.Empty; switch (ToNeonLevel(logLevel)) { case LogLevel.Critical: if (e == null) { LogCritical(message); } else { LogCritical(message, e); } break; case LogLevel.Debug: case LogLevel.Transient: if (e == null) { LogDebug(message); } else { LogDebug(message, e); } break; case LogLevel.Error: if (e == null) { LogError(message); } else { LogError(message, e); } break; case LogLevel.Info: if (e == null) { LogInfo(message); } else { LogInfo(message, e); } break; case LogLevel.SError: if (e == null) { LogSError(message); } else { LogSError(message, e); } break; case LogLevel.SInfo: if (e == null) { LogSInfo(message); } else { LogSInfo(message, e); } break; case LogLevel.Warn: if (e == null) { LogWarn(message); } else { LogWarn(message, e); } break; } }
public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) => true;
/// <summary> /// Is logging enabled for this logger at this <paramref name="logLevel"/>? /// </summary> /// <param name="logLevel"></param> /// <returns></returns> public bool IsEnabled(Microsoft.Extensions.Logging.LogLevel logLevel) { var convertLogLevel = ConvertLogLevel(logLevel); return(IsEnabled(convertLogLevel)); }
public void Log <TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { System.Diagnostics.Debug.WriteLine($"[{eventId}] {formatter(state, exception)}"); _logDelegate($"[{eventId}] {formatter(state, exception)}\n"); }
/// <summary> /// Convert log level to NLog variant. /// </summary> /// <param name="logLevel">level to be converted.</param> /// <returns></returns> static NLogLevel ConvertLogLevel(LogLevel logLevel) => logLevel switch {
public static void Write(Microsoft.Extensions.Logging.LogLevel level, string message, Exception exception = null) { _Logger.Value.Log(level, 0, new Microsoft.Extensions.Logging.Internal.FormattedLogValues(message, new object[0]), exception, MessageFormatter); }
//--------------------------------------------------------------------- // ILogger implementation: /// <inheritdoc/> public void Log <TState>(Microsoft.Extensions.Logging.LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { logger.Log <TState>(logLevel, eventId, state, exception, formatter); }
/// <summary> /// Writes a log entry. /// </summary> /// <typeparam name="TState"></typeparam> /// <param name="logLevel">Entry will be written on this level.</param> /// <param name="eventId">Id of the event.</param> /// <param name="state">The entry to be written. Can be also an object.</param> /// <param name="exception">The exception related to this entry.</param> /// <param name="formatter">Function to create a <c>string</c> message of the <paramref name="state" /> and <paramref name="exception" />.</param> public void Log <TState>( mslogging.LogLevel logLevel , mslogging.EventId eventId , TState state , Exception exception , Func <TState, Exception, string> formatter ) { if (!this.IsEnabled(logLevel)) { return; } if (state == null && exception == null) { return; } if (RollbarScope.Current != null && RollbarLocator.RollbarInstance.Config.MaxItems > 0 ) { RollbarScope.Current.IncrementLogItemsCount(); if (RollbarScope.Current.LogItemsCount == RollbarLocator.RollbarInstance.Config.MaxItems) { // the Rollbar SDK just reached MaxItems limit, report this fact and pause further logging within this scope: RollbarLocator.RollbarInstance.Warning(RollbarScope.MaxItemsReachedWarning); return; } else if (RollbarScope.Current.LogItemsCount > RollbarLocator.RollbarInstance.Config.MaxItems) { // the Rollbar SDK already exceeded MaxItems limit, do not log for this scope: return; } } // let's custom build the Data object that includes the exception // along with the current HTTP request context: string message = null; if (formatter != null) { message = formatter(state, exception); } Rollbar.DTOs.Body payloadBody = null; if (!string.IsNullOrWhiteSpace(message)) { payloadBody = new DTOs.Body(new DTOs.Message(message)); } else { payloadBody = new DTOs.Body(exception); } Dictionary <string, object> customProperties = new Dictionary <string, object>(); customProperties.Add( "LogEventID" , $"{eventId.Id}" + (string.IsNullOrWhiteSpace(eventId.Name) ? string.Empty : $" ({eventId.Name})") ); if (exception != null && message != null) { customProperties.Add("LogMessage", message); } var currentContext = GetCurrentContext(); Dictionary <string, object> customRequestFields = null; if (currentContext != null) { customRequestFields = new Dictionary <string, object>(); customRequestFields.Add("httpRequestTimestamp", currentContext.Timestamp); if (currentContext.HttpAttributes != null) { customRequestFields.Add("httpRequestID", currentContext.HttpAttributes.RequestID); customRequestFields.Add("statusCode", currentContext.HttpAttributes.StatusCode); customRequestFields.Add("scheme", currentContext.HttpAttributes.Scheme); customRequestFields.Add("protocol", currentContext.HttpAttributes.Protocol); } } var requestDto = new DTOs.Request(customRequestFields, currentContext?.HttpAttributes); DTOs.Data dataDto = new DTOs.Data( config: RollbarLocator.RollbarInstance.Config , body: payloadBody , custom: customProperties , request: requestDto ) { Level = RollbarLogger.Convert(logLevel), }; // log the Data object (the exception + the HTTP request data): RollbarLocator.RollbarInstance.Log(dataDto); }