RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

MultiTextWriter?

Cheetah2003

Wanderer
MultiTextWriter?

Hey... not sure if this is a mono only thing, but MultiTextWriter doesn't seem to be properly catching all possible WriteLines? I dunno, everything is going into the Console.Log (I changed the core to always log to a file.)

But with my code to add datetime to each line just doesnt seem to be catching every newline. The FileLogger class doesn't catch them all either.

Anyone got an idea? Here's my revised MultiTextWriter class:

Code:
	public class MultiTextWriter : TextWriter
	{
		private List<TextWriter> m_Streams;
		private bool m_NewLineNeeded = true;

		public MultiTextWriter( params TextWriter[] streams )
		{
			m_Streams = new List<TextWriter>( streams );

			if( m_Streams.Count < 0 )
				throw new ArgumentException( "You must specify at least one stream." );
		}

		public void Add( TextWriter tw )
		{
			m_Streams.Add( tw );
		}

		public void Remove( TextWriter tw )
		{
			m_Streams.Remove( tw );
		}

		public override void Write( char ch )
		{
			if (m_NewLineNeeded)
			{
				for (int i = 0; i < m_Streams.Count; i++)
					m_Streams[i].Write(String.Format("[{0}] ", DateTime.Now.ToString("MMM d HH:mm")));
				m_NewLineNeeded = false;
			}
			for( int i = 0; i < m_Streams.Count; i++ )
				m_Streams[i].Write( ch );
		}

		public override void WriteLine( string line )
		{
			for (int i = 0; i < m_Streams.Count; i++)
			{
				if (m_NewLineNeeded)
					m_Streams[i].WriteLine(String.Format("[{0}] {1}", DateTime.Now.ToString("MMM d HH:mm"), line));
				else
					m_Streams[i].WriteLine(line);
			}
			m_NewLineNeeded = true;
		}

		public override void WriteLine( string line, params object[] args )
		{
			WriteLine( String.Format( line, args ) );
		}

		public override void WriteLine(char[] line)
		{
			WriteLine(String.Format("{0}", line));
		}

		public override void WriteLine(char ch)
		{
			WriteLine(String.Format("{0}", ch));
		}

		public override void WriteLine(object o)
		{
			WriteLine(o.ToString());
		}

		public override Encoding Encoding
		{
			get { return Encoding.Default; }
		}
	}

Here's a sample of my console output:

Code:
[/home/cheetah/runuo] luxray:40> mono RunUO.exe
[Dec 1 20:05] RunUO - [www.runuo.com] Version 2.0, Build 2891.35960
[Dec 1 20:05] Core: Running on .NET Framework Version 2.0.50727
Core: Unix environment detected
[Dec 1 20:05] Using: [CoreScripts] Version 1.4.1445.16106
[Dec 1 20:05] Scripts: Compiling C# scripts...done (cached)
[Dec 1 20:05] Scripts: Compiling VB.NET scripts...no files found.
[Dec 1 20:05] Scripts: Verifying...done (4498 items, 1024 mobiles)
XMLServerOptions.cs -- Version 1.0
Loading configuration file Data/ServerConfig.xml...
Configuration loaded!
[Dec 1 20:05] FSATS XML Configuration -- Version 1.0
Loading FSATS configuration from Data/FSATSConfig.xml...
FSATS configuration loaded.
[Dec 1 20:05] Rails 1.0 -- Waiting for World Load
[Dec 1 20:05] Regions: Loading...done
[Dec 1 20:05] World: Loading...done (462925 items, 40405 mobiles) (105.30 seconds)
Onsite Dueling System: DuelPoints loaded.
[Dec 1 20:07] Xanthos.Utilities.ConfigParser failed.
[Dec 1 20:07] Loading XmlDialog configuration
4 settings processed
TransferServer version 1.05 listening on port 2591
Remote Admin 1.0.1.6 -- Admin Channel on port 2592.
QuestLogger: No data to cache.
[Dec 1 20:07] UO Architect Server for RunUO 2.0 is currently disabled.
Loading XmlSpawner configuration
8 settings processed
Account Purge v1.0 Initialized -- Next Purge time in: 08:52:41.0323660
Listening: 127.0.0.1:2593
Listening: 10.0.0.6:2593
Time System: Version 2.0.5 loading...
[Dec 1 20:07] Time System: Logging is enabled.
[Dec 1 20:07] Time System: Calculated managed lights list and found 1127 lights.
[Dec 1 20:07] Time System: Loading complete.
[Dec 1 20:07] Time System: It is 4:48 AM on the 20th of January, 6. The moon is new.
[Dec 1 20:07] Rails 1.0 -- Initializing rails
[Dec 1 20:07] Rails 1.0 -- Initialized 0 NPCs with rails
 

Setharnas

Sorceror
I don't know, that code works flawlessly on my SVN 181 server on WinXP. Maybe a Mono thing?

BTW, kudos for posting something I pm'ed you about... oh, half a year ago? ;)
 

Cheetah2003

Wanderer
Setharnas;727486 said:
I don't know, that code works flawlessly on my SVN 181 server on WinXP. Maybe a Mono thing?

BTW, kudos for posting something I pm'ed you about... oh, half a year ago? ;)

I was out of it for quite a while. What did I post about? Hehe.
 

Setharnas

Sorceror
Yeah, I realized that when your 'last activity' date didn't change anymore. ;)

It was nothing specific, just some error logs you posted with that timestamp already included. I just sent you a pm asking what to do in order to get that, too. Very useful thing IMO, should be distro default.

It wasn't meant as ironic when I wrote that line, I'm glad to finally have an answer. :)
 
Top