private string ProcessTemplate(string inputFile, TextTemplatingCallback handler)
    {
        var output = _host.ProcessTemplate(
            inputFile,
            File.ReadAllText(inputFile),
            handler);

        foreach (CompilerError error in handler.Errors)
        {
            var builder = new StringBuilder();

            if (!string.IsNullOrEmpty(error.FileName))
            {
                builder.Append(error.FileName);

                if (error.Line > 0)
                {
                    builder
                    .Append("(")
                    .Append(error.Line);

                    if (error.Column > 0)
                    {
                        builder
                        .Append(",")
                        .Append(error.Line);
                    }
                    builder.Append(")");
                }

                builder.Append(" : ");
            }

            builder
            .Append(error.IsWarning ? "warning" : "error")
            .Append(" ")
            .Append(error.ErrorNumber)
            .Append(": ")
            .AppendLine(error.ErrorText);

            if (error.IsWarning)
            {
                _reporter.WriteWarning(builder.ToString());
            }
            else
            {
                _reporter.WriteError(builder.ToString());
            }
        }

        if (handler.OutputEncoding != Encoding.UTF8)
        {
            _reporter.WriteWarning(DesignStrings.EncodingIgnored(handler.OutputEncoding.WebName));
        }

        return(output);
    }
Exemplo n.º 2
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual void Log <TState>(
            LogLevel logLevel,
            EventId eventId,
            TState state,
            Exception exception,
            Func <TState, Exception, string> formatter)
        {
            // Only show SQL when verbose
            if (_categoryName == DbLoggerCategory.Database.Command.Name &&
                eventId.Id == RelationalEventId.CommandExecuted.Id)
            {
                logLevel = LogLevel.Debug;
            }

            var message = GetMessage(state, exception, formatter);

            switch (logLevel)
            {
            case LogLevel.Critical:
            case LogLevel.Error:
                _reporter.WriteError(message);
                break;

            case LogLevel.Warning:
                _reporter.WriteWarning(message);
                break;

            case LogLevel.Information:
                _reporter.WriteInformation(message);
                break;

            default:
                _reporter.WriteVerbose(message);
                break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual void Log <TState>(
            LogLevel logLevel,
            EventId eventId,
            TState state,
            Exception exception,
            Func <TState, Exception, string> formatter)
        {
            // Only show SQL when verbose
            if (_categoryName == typeof(RelationalCommandBuilderFactory).FullName &&
                eventId.Id == (int)RelationalEventId.ExecutedCommand)
            {
                logLevel = LogLevel.Debug;
            }

            var message = GetMessage(state, exception, formatter);

            switch (logLevel)
            {
            case LogLevel.Critical:
            case LogLevel.Error:
                _reporter.WriteError(message);
                break;

            case LogLevel.Warning:
                _reporter.WriteWarning(message);
                break;

            case LogLevel.Information:
                _reporter.WriteInformation(message);
                break;

            default:
                _reporter.WriteVerbose(message);
                break;
            }
        }