log4net停止处理单独的任务

时间:2018-05-31 09:20:16

标签: c# log4net log4net-configuration

我有这个代码用于log4net,它适用于几行但在此之后停止工作,这很奇怪!

这是代码

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    var mysql = require('mysql');

    var con = mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "123",
        database: "mydb"
    });

    con.connect(function(err) {
        if (err) throw err;

        var sql = "SELECT users.name AS user, products.name AS favorite FROM users JOIN products ON users.favorite_product = products.id";

        con.query(sql, function (err, result) {
            if (err) throw err;
            console.log('hello world');
        });
    });
}).listen(8080);

Logger的第一行由log4net appender记录,但后面的Task.Factory.StratNew行停止工作。

令人惊讶的是,相同的代码在Console应用程序中有效,但当移动到Windows服务时,它会停止记录。

这是错的!

[UPDATE1] Log4net config

public void SyncPR5600(int serviceId)
{
    Logger.Info("Starting execution of {0} out of task");
    Task.Factory.StartNew(() =>
    {
        string tableName = "PR5600";
        Logger.Info(string.Format("Starting execution of {0}", tableName));    
    });
}

1 个答案:

答案 0 :(得分:0)

我的代码与TaskCreationOptions.AttachedToParent选项一起使用。有趣的是,即使没有该选项,在VS2017调试模式下运行也会生成日志。

# The necessary filter to get that array should be something along these lines
item['block_device_mapping'] | list() | join(', ')