Exemplo n.º 1
0
        async Task <LogWriteOperation[]> LogInternal(LogLevel level, string message, object[] ps, Exception ex, bool doFormat)
        {
            try
            {
                if (_configuration.IsEnabled == false)
                {
                    return(EmptyOperations);
                }
                var targets = _configuration.GetTargets(level);
                if (!(targets.Any()))
                {
                    return(EmptyOperations);
                }

                // format?
                if (doFormat)
                {
                    message = string.Format(message, ps);
                }

                // create an event entry and pass it through...
                var entry = new LogEventInfo(level, Name, message, ex);

                // create a context...
                var context = new LogWriteContext();

                // gather the tasks...
                var writeTasks = from target in targets
                                 select target.WriteAsync(context, entry);

                // group...
                var group = await Task.WhenAll(writeTasks).ConfigureAwait(false);

                return(group);
            }
            catch (Exception logEx)
            {
                InternalLogger.Current.Error("Logging operation failed.", logEx);
                return(EmptyOperations);
            }
        }