4

我的 css 有问题,因为编译后没有样式被添加到我的网站。

如何让 dotlesscss 显示错误?常规 .less 向您显示一条非常方便的好消息。

4

2 回答 2

5

您可以使用 web.config 轻松完成此操作。在您的无点配置部分中,添加以下内容:logger="dotless.Core.Loggers.AspResponseLogger". 这将使无点输出错误而不是空白 css。

我已将以下内容作为示例。(“...”代表 web.config 中的现有内容)。在我下面的示例中,缓存设置为 false。这对于调试目的很有用。在正常情况下,它可能应该设置为 true。

<configuration>    
     <configSections>
           ...
          <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
      </configSections>

      <dotless minifyCss="false" cache="false" 
            logger="dotless.Core.Loggers.AspResponseLogger" />
       ...    
</configuration>    
于 2012-05-17T19:20:44.880 回答
4

我今天在我的RequestReduce项目中遇到了这个问题。我得到了更少的空白 - > css 转换,因为似乎有解析错误进入以太。感谢这个相关的答案How can I output errors when using .less programmatically? 我能够制定出一个解决方案,我可以将错误写入响应流。您必须创建一个从 dotless.Core.Loggers.ILogger 派生的 Logger:

public class LessLogger : ILogger
{
    public void Log(LogLevel level, string message)
    {
    }

    public void Info(string message)
    {
    }

    public void Debug(string message)
    {
    }

    public void Warn(string message)
    {
    }

    public void Error(string message)
    {
        Response.Write(message);
    }

    public HttpResponseBase Response { get; set; }
}

您将其传递到发送到 EngineFactory 的配置中:

            var engine = new EngineFactory(new DotlessConfiguration
                                               {
                                                   CacheEnabled = false,
                                                   Logger = typeof (LessLogger)
                                               }
                ).GetEngine();

出于单元测试的目的,我想传入会写错误的 HttpResponseBase。这就是我觉得通过一些讨厌的铸造来获得对我的记录器的引用的事情变得丑陋的地方:

            ((LessLogger)((LessEngine)((ParameterDecorator)engine).Underlying).Logger).Response = response;

我希望这能够帮到你。

于 2011-12-09T17:33:22.733 回答