IronPDF中AWS日誌檔案的疑難排解
使用S3 Bucket隔離IronPDF日誌
當在AWS環境中進行IronPDF疑難排解時,獲取來自IronPDF程式庫的乾淨、專用日誌是非常有幫助的。 此方法有助於避免從Amazon CloudWatch Logs或AWS Application Insights等服務中挑選合併的日誌流的複雜性。
服務如CloudWatch Logs和Application Insights通常會彙總來自各種來源的日誌,包括您的應用程式碼、其他程式庫和AWS服務。 這種交錯可能使得直接找出IronPDF特定的消息並診斷與PDF生成或操作相關的問題變得困難。
為了克服這些挑戰,我們建議配置IronPDF將其日誌寫入您AWS計算環境的臨時儲存中的專用檔案中。 此獨立的日誌檔案可以輕鬆上傳到Amazon S3 Bucket,以便需要時方便下載、審查和與支援分享。
啟用和配置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"
將日誌檔案上傳到Amazon S3 Bucket
// 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
關於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

