NLog在其他项目中使用时不创建日志

时间:2017-05-17 09:22:54

标签: c# asp.net asp.net-mvc logging

我有一个类库Project,我正在使用类11:13:04 **** Incremental Build of configuration Debug for project Vec2 **** make all Building file: ../Vec2.cpp Invoking: GCC C++ Compiler g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Vec2.d" -MT"Vec2.o" -o "Vec2.o" "../Vec2.cpp" ../Vec2.cpp: In member function ‘Vec2 Vec2::operator+(const Vec2&)’: ../Vec2.cpp:15:11: error: no matching function for call to ‘Vec2::Vec2()’ Vec2 newv; ^~~~ ../Vec2.cpp:8:2: note: candidate: Vec2::Vec2(float, float) Vec2(float a,float b):x1(a),x2(b){} ^~~~ ../Vec2.cpp:8:2: note: candidate expects 2 arguments, 0 provided ../Vec2.cpp:3:7: note: candidate: constexpr Vec2::Vec2(const Vec2&) class Vec2 ^~~~ ../Vec2.cpp:3:7: note: candidate expects 1 argument, 0 provided ../Vec2.cpp:3:7: note: candidate: constexpr Vec2::Vec2(Vec2&&) ../Vec2.cpp:3:7: note: candidate expects 1 argument, 0 provided make: *** [subdir.mk:20: Vec2.o] Error 1 11:13:05 Build Finished (took 422ms) 并使用Class1方法打印日志。

di

现在我在这里有另一个项目我正在使用方法di的classlibrary项目引用但是当我使用di时,它不会创建日志文件。

public class Class1
{
    private static Logger logger = LogManager.GetCurrentClassLogger();
    public void di()
    {
        var config = new LoggingConfiguration();

        var fileTarget = new FileTarget();
        config.AddTarget("file", fileTarget);

        fileTarget.FileName = "${basedir}/test.txt";
        fileTarget.Layout = "${longdate} ${message}";

        var rule2 = new LoggingRule("*", LogLevel.Debug, fileTarget);
        config.LoggingRules.Add(rule2);
        LogManager.Configuration = config;
        // logger = LogManager.GetLogger("Testing");
        logger.Trace("Testing");
        // add log message
    }
}

1 个答案:

答案 0 :(得分:0)

类库的 app.config 文件中必须有一些关于 NLog 的设置。如果您在 web.config 中复制这些设置,那么它将按照您的期望开始工作。