Troubleshooting AWS Log Files in IronPDF

This article was translated from English: Does it need improvement?
Translated
View the article in English

使用S3桶隔離IronPDF日誌

當在AWS環境中對IronPDF進行故障排除時,獲取來自IronPDF庫的乾淨且專用的日誌非常有用。 這種方法有助於避免通過Amazon CloudWatch Logs或AWS Application Insights等服務的合併日誌流的複雜性。

像CloudWatch Logs和Application Insights這樣的服務通常會聚合來自各種來源的日誌,包括您的應用程序代碼、其他庫和AWS服務。 這種交錯可能使得難以準確查找IronPDF特定消息並診斷PDF生成或操作相關的問題。

為了克服這些挑戰,我們建議配置IronPDF將其日誌寫入到AWS計算環境的臨時存儲內的專用文件中。 然後可以輕鬆地將此隔離的日誌文件上傳到Amazon S3桶以方便下載、查看和在需要時與支持共享。

啟用和配置IronPDF日誌記錄

var awsTmpPath = @"/tmp/";

IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.All;
IronSoftware.Logger.LogFilePath = awsTmpPath + "default.txt";
var awsTmpPath = @"/tmp/";

IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.All;
IronSoftware.Logger.LogFilePath = awsTmpPath + "default.txt";
Dim awsTmpPath = "/tmp/"

IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.All
IronSoftware.Logger.LogFilePath = awsTmpPath & "default.txt"
$vbLabelText   $csharpLabel

將日誌文件上傳到Amazon S3桶

// File path in the Lambda /tmp directory
var filePath = $"/tmp/default.txt";

// Read the file as byte array
var fileBytes = await File.ReadAllBytesAsync(filePath);

// Upload the text file to S3
using (var memoryStream = new MemoryStream(fileBytes))
{
    var request = new PutObjectRequest
    {
        BucketName = bucketName,
        Key = "default.txt",
        InputStream = memoryStream,
        ContentType = "text/plain",
    };

    await _s3Client.PutObjectAsync(request);
}
// File path in the Lambda /tmp directory
var filePath = $"/tmp/default.txt";

// Read the file as byte array
var fileBytes = await File.ReadAllBytesAsync(filePath);

// Upload the text file to S3
using (var memoryStream = new MemoryStream(fileBytes))
{
    var request = new PutObjectRequest
    {
        BucketName = bucketName,
        Key = "default.txt",
        InputStream = memoryStream,
        ContentType = "text/plain",
    };

    await _s3Client.PutObjectAsync(request);
}
' File path in the Lambda /tmp directory
Dim filePath = $"/tmp/default.txt"

' Read the file as byte array
Dim fileBytes = Await File.ReadAllBytesAsync(filePath)

' Upload the text file to S3
Using memoryStream As New MemoryStream(fileBytes)
	Dim request = New PutObjectRequest With {
		.BucketName = bucketName,
		.Key = "default.txt",
		.InputStream = memoryStream,
		.ContentType = "text/plain"
	}

	Await _s3Client.PutObjectAsync(request)
End Using
$vbLabelText   $csharpLabel

有關AWS特定日誌服務,請參閱以下文檔:

Amazon CloudWatch

Amazon CloudWatch Logs服務允許您在接近實時的情況下收集和存儲您的資源、應用程序和服務的日誌。

附加日誌

如需進一步瞭解Amazon CloudWatch Logs,Amazon S3 Logs和發送到Kinesis Data Firehose的日誌,請參閱:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html

常用服務

AWS Lambda

https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html

Amazon EC2

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 16,154,058 | 版本: 2025.11 剛剛發布