50 |
|
private MemoryStream ms; |
51 |
|
private StreamWriter sw; |
52 |
|
private StreamReader sr; |
53 |
< |
|
53 |
> |
private bool _AutoScroll; |
54 |
> |
new public bool AutoScroll { get { return _AutoScroll; } set { _AutoScroll = value; autoscroll_timer.Enabled = value; } } |
55 |
|
|
56 |
|
private bool _RedirectConsoleOutput; |
57 |
|
public bool RedirectConsoleOutput |
144 |
|
else { writer.Write(value); } |
145 |
|
writer.Close(); |
146 |
|
sw.Write(value); |
147 |
+ |
Application.DoEvents(); |
148 |
|
} |
149 |
+ |
|
150 |
|
new public string Text |
151 |
|
{ |
152 |
|
get |
166 |
|
if (fi.Exists) |
167 |
|
fi.Delete(); |
168 |
|
} |
169 |
< |
Log.WriteLine("{0} ({2} v{3} {4}) created on {1}", LoggingConstants.AppLogFile, DateTime.Now.ToString(), LoggingConstants.AppName, LoggingConstants.AppVersion, LoggingConstants.AppBuild); |
169 |
> |
Log.WriteLine("{0} ({2} v{3} {4}) created on {1}", LoggingConstants.AppLogFile, DateTime.Now.ToString(), LoggingConstants.AppName, LoggingConstants.AppVersion, LoggingConstants.AppBuild); |
170 |
|
} |
171 |
|
public void Clear() |
172 |
|
{ |
191 |
|
#region sub-classes |
192 |
|
public class LogStream : TextWriter |
193 |
|
{ |
194 |
+ |
private StringBuilder strMessage = new StringBuilder(); |
195 |
|
public LogStream() : this(null) { } |
196 |
|
public LogStream(LogWriter text) : base() { _text_writer = text; this.NewLine = "\n"; } |
197 |
|
private LogWriter _text_writer; |
198 |
< |
private void _write(string message) { if (_text_writer == null) return; _text_writer.SetLogText(string.Format("{0}", message)); } |
198 |
> |
private void _write(string message) |
199 |
> |
{ |
200 |
> |
if (_text_writer == null) return; |
201 |
> |
|
202 |
> |
if (message.EndsWith("\n")) |
203 |
> |
{ |
204 |
> |
//_text_writer.SetLogText(string.Format("{0}", strMessage.ToString())); |
205 |
> |
while (_text_writer.logupdater.IsBusy) |
206 |
> |
{ |
207 |
> |
Application.DoEvents(); |
208 |
> |
} |
209 |
> |
_text_writer.logupdater.RunWorkerAsync((string.Format("{0}", strMessage.ToString()))); |
210 |
> |
strMessage = new StringBuilder(); |
211 |
> |
} |
212 |
> |
strMessage.Append(message); |
213 |
> |
} |
214 |
|
#region Overriden Methods |
215 |
|
public override Encoding Encoding { get { return Encoding.UTF8; } } |
216 |
|
public override void Write(char value) { base.Write(value); _write(value.ToString()); if (!_text_writer.BeginUpdate) _text_writer.EndLogUpdate(); } |
217 |
|
#endregion |
218 |
|
} |
219 |
|
#endregion |
220 |
+ |
|
221 |
+ |
private void autoscroll_timer_Tick(object sender, EventArgs e) |
222 |
+ |
{ |
223 |
+ |
if (this.DesignMode) { return; } |
224 |
+ |
//txtLog.ScrollToEnd(); |
225 |
+ |
//txtLog.SelectionStart = txtLog.Text.Length-100; |
226 |
+ |
//txtLog.ScrollToCaret(); |
227 |
+ |
//txtLog.Refresh(); |
228 |
+ |
|
229 |
+ |
txtLog.SelectionStart = 0; |
230 |
+ |
txtLog.ScrollToCaret(); |
231 |
+ |
txtLog.Refresh(); |
232 |
+ |
|
233 |
+ |
int last_line_position = -1; |
234 |
+ |
int position = -1; |
235 |
+ |
int len = txtLog.Text.Length; |
236 |
+ |
StringReader sr = new StringReader(this.StreamToString()); |
237 |
+ |
string line = ""; |
238 |
+ |
while ((line = sr.ReadLine()) != null) |
239 |
+ |
{ |
240 |
+ |
position += (line.Length); |
241 |
+ |
last_line_position = (line.Length*2); |
242 |
+ |
//if (line.EndsWith("/n")) |
243 |
+ |
//{ |
244 |
+ |
// position++; |
245 |
+ |
//} |
246 |
+ |
//logger.VerboseDebug.WriteLine("current line: {0}", line); |
247 |
+ |
} |
248 |
+ |
txtLog.SelectionStart = position; |
249 |
+ |
txtLog.ScrollToCaret(); |
250 |
+ |
txtLog.Refresh(); |
251 |
+ |
//autoscroll_timer.Enabled = false; |
252 |
+ |
} |
253 |
+ |
|
254 |
+ |
private void logupdater_DoWork(object sender, DoWorkEventArgs e) |
255 |
+ |
{ |
256 |
+ |
string message = e.Argument.ToString(); |
257 |
+ |
SetLogText(string.Format("{0}", message)); |
258 |
+ |
} |
259 |
+ |
|
260 |
+ |
private void logupdater_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
261 |
+ |
{ |
262 |
+ |
|
263 |
+ |
} |
264 |
|
} |
265 |
|
} |
266 |
+ |
|