在 IronPDF 中排除 AWS 日誌檔案的疑難排解

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 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備開始了嗎?
Nuget 下載 19,014,616 | 版本: 2026.5 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronPdf
執行範例 觀看您的 HTML 轉為 PDF。