簡體   English   中英

Elsa 工作流程寫入日志文件

[英]Elsa workflow write to a log file

我想寫入 Elsa 工作流程中的日志文件。 我想知道是否有人有他們如何能夠在 Elsa 工作流程中寫入日志文件的示例。 我試圖使用 OutFile 活動,但我想知道是否有人有使用此活動寫入文件的示例,或者是否有其他選項可以在 Elsa 工作流程中寫入日志文件

我發現處理此問題的最佳方法是在代碼中創建自定義活動。 這是創建的 class:

[Action(
Category = "File",
DisplayName = "Write to File",
Description = "Writes text to a file")]
public class WriteToFile : Activity
{
    [Required]
    [ActivityInput(Hint = "Text to write to file.", UIHint = ActivityInputUIHints.SingleLine, SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
    public string Text { get; set; } = default!;

    [Required]
    [ActivityInput(Hint = "Path of the file to write to.", UIHint = ActivityInputUIHints.SingleLine, SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
    public string FilePath { get; set; } = default!;

    [ActivityInput(Hint = "How to handle an existing file.", UIHint = ActivityInputUIHints.Dropdown, DefaultValue = CopyMode.Append)]
    public CopyMode Mode { get; set; }

    public override async ValueTask<IActivityExecutionResult> ExecuteAsync(ActivityExecutionContext context)
    {
        using (StreamWriter file = new(FilePath, append: Mode == CopyMode.Append))
        {
            await file.WriteLineAsync(Text);
        };

        return Done();
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM