I have a problem with the manipulation of the information in a plain text log file, I try to save the properties of each file log in a c # model, and then save the models that have been generated in a list of the same type , I already manage to obtain and save the information in the models using a cycle, the problem is that if at the end I had 20 logs, the list will contain the same amount but in all it shows me only the information of the last log, when updating the object with every iteration all those that have been saved before are also updated, I look for a way so that once saved data stays as it is in the list and continues like this with the others
Annex what I get
GlobalVariables.ListMo
Count = 5
[0]: {ConsoleApp1.Modelos.Class1}
[1]: {ConsoleApp1.Modelos.Class1}
[2]: {ConsoleApp1.Modelos.Class1}
[3]: {ConsoleApp1.Modelos.Class1}
[4]: {ConsoleApp1.Modelos.Class1}
GlobalVariables.ListMo[0]
{ConsoleApp1.Modelos.Class1}
ClaseGeneradora: "DetalleUsuarioDataAccess"
DirectorioBase: "C:\repositorio\********\******\ "
FechaLog: "2018-08-13 16:46:56.1607 "
LugarDeLlamada: "BusinessLogic.Logs.DireccionamientoLogs.EscribirLogRegistro "
MensajeObtenido: "El usuario 2 realiz� un nuevo registr� en 'UsuarioDetalles' con el ID: 52 "
Tipo: "INFO "
GlobalVariables.ListMo[1]
{ConsoleApp1.Modelos.Class1}
ClaseGeneradora: "GuardarDetalle "
DirectorioBase: "C:\repositorio\************\********\ "
FechaLog: "2018-08-13 16:46:56.1607 "
LugarDeLlamada: "BusinessLogic.Logs.DireccionamientoLogs.EscribirLogRegistro "
MensajeObtenido: "El usuario 2 realiz� un nuevo registr� en 'UsuarioDetalles' con el ID: 52 "
Tipo: "INFO "
In all there is the same information, but each one has different properties.
These are the methods with which I read and add the model and the list
private List<Class1> ContenidoArchivo(string path)
{
StreamReader objReader = new StreamReader(path);
string linea = "";
int cont = 0;
while (linea != null)
{
linea = objReader.ReadLine();
if (linea != null)
{
QuitarAtributos(linea);
cont++;
}
if (cont ==6)
{
GlobalVariables.ListMo.Add(modelo);
cont = 0;
}
}
objReader.Close();
return null;
}
private void QuitarAtributos(string linea)'
{
if (linea.Contains("FechaLog:"))
{
modelo.FechaLog = linea.Replace("FechaLog:", "");
}
if (linea.Contains("Tipo:"))
{
modelo.Tipo = linea.Replace("Tipo:", "");
}
if (linea.Contains("ClaseGeneradora:"))
{
modelo.ClaseGeneradora = linea.Replace("ClaseGeneradora:", "");
}
if (linea.Contains("LugarDeLlamada:"))
{
modelo.LugarDeLlamada = linea.Replace("LugarDeLlamada:", "");
}
if (linea.Contains("MensajeObtenido:"))
{
modelo.MensajeObtenido = linea.Replace("MensajeObtenido:", "");
}
if (linea.Contains("DirectorioBase:"))
{
modelo.DirectorioBase = linea.Replace("DirectorioBase:", "");
}
}
This is a view of how the file is written
FechaLog:2018-08-13 16:01:36.3557
Tipo:INFO
ClaseGeneradora:GuardarUsuario
LugarDeLlamada:BusinessLogic.Logs.DireccionamientoLogs.EscribirLogRegistro
MensajeObtenido:El usuario 2 realizó un nuevo registró en 'Usuarios' con el ID: 123
DirectorioBase:C:\repositorio\*******\*******\
FechaLog:2018-08-13 16:18:04.2844
Tipo:INFO
ClaseGeneradora:GuardarTipo
LugarDeLlamada:BusinessLogic.Logs.DireccionamientoLogs.EscribirLogRegistro
MensajeObtenido:El usuario 2 realizó un nuevo registró en 'TipoUsuarios' con el ID: 61
DirectorioBase:C:\repositorio\*******\*******\
FechaLog:2018-08-13 16:40:11.2955
Tipo:INFO
ClaseGeneradora:GuardarRol
LugarDeLlamada:BusinessLogic.Logs.DireccionamientoLogs.EscribirLogRegistro
MensajeObtenido:El usuario 2 realizó un nuevo registró en 'RolUsuario' con el ID: 44
DirectorioBase:C:\repositorio\*******\*******\
FechaLog:2018-08-13 17:01:37.0273
Tipo:INFO
ClaseGeneradora:GuardarUsuario
LugarDeLlamada:BusinessLogic.Logs.DireccionamientoLogs.EscribirLogRegistro
MensajeObtenido:El usuario 2 realizó un nuevo registró en 'Usuarios' con el ID: 126
DirectorioBase:C:\repositorio\*******\*******\
FechaLog:2018-08-13 16:46:56.1607
Tipo:INFO
ClaseGeneradora:GuardarDetalle
LugarDeLlamada:BusinessLogic.Logs.DireccionamientoLogs.EscribirLogRegistro
MensajeObtenido:El usuario 2 realizó un nuevo registró en 'UsuarioDetalles' con el ID: 52
DirectorioBase:C:\repositorio\*******\*******\
Thanks from now on