Azure WebJob 不写入输出

Azure WebJob not writing to output

我有一个 Azure WebJob,当我在本地调试它时正在写入输出,但当我 运行 在 Azure 中时它没有。输出 blob 容器完全为空,scm.azurewebsites.net 站点中的输出 window 呈灰色和空白。我是否需要进行任何设置才能将我的输出发送到那里?

这是它们的截图:

这是我在 Webjob 上 运行 的代码:

public static void InsertSQLData([BlobTrigger("blobcontainer/{name}")] Stream input, string name)
{
    var sw = new Stopwatch();
    sw.Start();

    RetryAbleBCP rtbcp = new RetryAbleBCP(input,
         "dbo.FullText",
        ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString,
        SqlBulkCopyOptions.Default, 
        ',', 
        500, 
        null);
    try
    {
        rtbcp.BulkInsertCSV();
    }
    catch (OutOfMemoryException eoom)
    {
        Console.WriteLine(eoom.Message);
    }
    catch (IOException eio)
    {
        Console.WriteLine(eio.Message);
    }
    catch (InvalidOperationException eiop)
    {
        Console.WriteLine(string.Format("Row {0}: {1}", rtbcp.NumRowsRead, eiop.Message));
    }
    catch (SqlException se)
    {
        Console.WriteLine(se.Message);
    }
    catch (Exception e)
    {
        Console.WriteLine(string.Format("General Application Exception: {0}", e.Message));
    }

    sw.Stop();
    Console.Out.WriteLine("Finished Batch Insert.  Elapsed: {0}ms", sw.ElapsedMilliseconds);           
}

在您的代码中,您正在使用 Console.WriteLine() 编写日志。要在 WebJobs 仪表板中显示输出,请使用 TextWriter,如下所示:

public static void InsertSQLData([BlobTrigger("blobcontainer/{name}")] Stream input,
                                 string name, TextWriter log)
{
    // ...
    log.WriteLine("some message");
}