lcrok opened a new issue, #252:
URL: https://github.com/apache/logging-log4net/issues/252
Our application is running on a Kubernetes cluster in a microservice
architecture. We need to send some data from log files created in the pod to
Elasticsearch using Filebeat.
- We have a pod with the application running and writing the logs to a
folder.
- We have a sidecar container running Filebeat that have the same folder the
application is writing the logs, but in read-only.
- We currently have 5 replicas of the application.
The issue:
Log4Net in some pods produces the logs correctly, like this one:
```
-rw-r--r--. 1 root root 36932982 Jun 2 18:21 HierarchicalLog.json
-rw-r--r--. 1 root root 52430863 Jun 2 09:03 HierarchicalLog.json.1
-rw-r--r--. 1 root root 52431967 Jun 1 19:49 HierarchicalLog.json.2
-rw-r--r--. 1 root root 52432590 Jun 1 07:18 HierarchicalLog.json.3
-rw-r--r--. 1 root root 52431608 May 31 18:07 HierarchicalLog.json.4
-rw-r--r--. 1 root root 52436224 May 31 05:34 HierarchicalLog.json.5
```
On some other pods, it writes to more files at the same time:
```
-rw-r--r--. 1 root root 35990140 Jun 2 18:21 HierarchicalLog.json
-rw-r--r--. 1 root root 35990140 Jun 2 18:21 HierarchicalLog.json.1
-rw-r--r--. 1 root root 35990140 Jun 2 18:21 HierarchicalLog.json.2
-rw-r--r--. 1 root root 35990140 Jun 2 18:21 HierarchicalLog.json.3
-rw-r--r--. 1 root root 35990140 Jun 2 18:21 HierarchicalLog.json.4
-rw-r--r--. 1 root root 35990140 Jun 2 18:21 HierarchicalLog.json.5
```
or
```
-rw-r--r--. 1 root root 36115523 Jun 2 18:26 HierarchicalLog.json
-rw-r--r--. 1 root root 36115523 Jun 2 18:26 HierarchicalLog.json.1
-rw-r--r--. 1 root root 52430146 Jun 2 09:22 HierarchicalLog.json.2
-rw-r--r--. 1 root root 52430146 Jun 2 09:22 HierarchicalLog.json.3
-rw-r--r--. 1 root root 52430986 Jun 1 20:05 HierarchicalLog.json.4
-rw-r--r--. 1 root root 52430986 Jun 1 20:05 HierarchicalLog.json.5
```
_In this case it is writing to the first 2 files at the same time_
The problem apear to not be related to Filebeat, as we have already tested
removing the sidecar and the shared mapping and the issue still occur.
Anyone have seen anything similar on a containerized multi-instance scenario?
The log4net config is like this:
```
private ILog GetLogger(string businessFunctionType)
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var loggerName = $"Logger_{businessFunctionType}";
var appenderName = $"FileAppender_{businessFunctionType}";
var logFilePath =
$"var/log/{businessFunctionType}/HierarchicalLog.json";
var logger = LogManager.GetLogger(loggerName);
// Check if the appender already exists
if (hierarchy.GetLogger(loggerName) is Logger log &&
log.GetAppender(appenderName) == null)
{
var fileAppender = new RollingFileAppender
{
Name = appenderName, // FileAppender_BusinessA
File = logFilePath, //
var/log/BusinessA/HierarchicalLog.json
AppendToFile = true,
MaxSizeRollBackups =
GetMaxSizeRollBackups(businessFunctionType), // 70
MaximumFileSize =
GetMaximumFileSize(businessFunctionType), // 50MB
RollingStyle = GetRollingStyle(businessFunctionType), //
Size
StaticLogFileName = true,
Layout = new HierarchicalLogJsonLayout() // json format
};
fileAppender.ActivateOptions();
log.AddAppender(fileAppender);
log.Level = log4net.Core.Level.All;
log.Hierarchy.Configured = true;
}
return logger;
}
----------------------------------------------------
In summary:
Name = FileAppender_BusinessA
File = "var/log/BusinessA/HierarchicalLog.json",
AppendToFile = true,
MaxSizeRollBackups = "70"
MaximumFileSize = "50MB"
RollingStyle = "Size"
StaticLogFileName = true,
Layout = new HierarchicalLogJsonLayout()
```
Any help would be appreciated.
Thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]