The official Fatica Labs Blog! RSS 2.0
# Saturday, December 04, 2010

Ho appreso da un mio collega l’esistenza del comando unix/linux tail, che com il flag –f monitora costantemente un file e scrive a console le nuove linee aggiunte. Questo è ottimo se si sta seguendo realtime un log su file. L’unico problema di questa soluzione è che – almeno nell ‘ implementazione che abbiamo usato-  usando il RollingFileAppender di log4net il file rimaneva locked, e durante la rinomina automatica falliva e si rischiava di perdere comopletamente un segmento di log.

A tale scopo ho scritto una piccola utility C# che fa esattamente la stessa cosa di tail –f, che troavate su codeplex a questo indirizzo.

Una breve descrizione della command line:

 

  • tailf mylog.txt continuously dump on the console the content of mylog.txt as soon new lines are written into it.
  • tailf -n:15 mylog.txt continuously dump on the console the content of mylog.txt as soon new lines are written into it. At startup the last 15 lines are dumped.
  • tailf mylog.txt -f:ERROR continuously dump on the console the content of mylog.txt as soon new lines are written into it. Just lines containing "ERROR" are shown.
  • tailf mylog.txt -f:"ERROR|WARN" continuously dump on the console the content of mylog.txt as soon new lines are written into it. Just lines containing "ERROR" or "WARN" are shown; double quotes are necessary since | is a special char in the command shell.
Per avere invece al volo un idea di come usare il codice per altri scopi date un’ occhiata qui.
Saturday, December 04, 2010 6:04:53 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] - Trackback
log4net

My Stack Overflow
Contacts

Send mail to the author(s) E-mail

Tags
profile for Felice Pollano at Stack Overflow, Q&A for professional and enthusiast programmers
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2013
Felice Pollano
Sign In
Statistics
Total Posts: 157
This Year: 3
This Month: 0
This Week: 0
Comments: 125
This blog visits
All Content © 2013, Felice Pollano
DasBlog theme 'Business' created by Christoph De Baene (delarou) and modified by Felice Pollano