You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Son Tran (JIRA)" <ji...@apache.org> on 2014/05/11 00:15:46 UTC
[jira] [Commented] (LOG4NET-412) Millisecond always return 0 in
wince
[ https://issues.apache.org/jira/browse/LOG4NET-412?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13993466#comment-13993466 ]
Son Tran commented on LOG4NET-412:
----------------------------------
I add new class DateTimeMs to get millisecond in netcf. And change LoggingEvent function like this:
public LoggingEvent(Type callerStackBoundaryDeclaringType, log4net.Repository.ILoggerRepository repository, string loggerName, Level level, object message, Exception exception)
{
m_callerStackBoundaryDeclaringType = callerStackBoundaryDeclaringType;
m_message = message;
m_repository = repository;
m_thrownException = exception;
m_data.LoggerName = loggerName;
m_data.Level = level;
// Store the event creation time
#if !NETCF
m_data.TimeStamp = DateTime.Now;
#else
m_data.TimeStamp = DateTimeMs.NowMs;
#endif
}
/*
* patch to get from opennetcf blog
*/
using System;
namespace log4net.Core
{
public class DateTimeMs
{
private static int m_offset = 0;
private static long systemStartMS = 0;
/* ticks correction constant (*1000). Default is 1000 - no correction */
public static long TimeScaleThousands { get; set; }
static DateTimeMs()
{
DateTimeMs.TimeScaleThousands = 1000;
Reset();
CalculateOffset();
}
public static long TickCount
{
get
{
return ((long)Environment.TickCount) * DateTimeMs.TimeScaleThousands / 1000;
}
}
public static void CalculateOffset()
{
int s = DateTime.Now.Second;
while (true)
{
int s2 = DateTime.Now.Second;
// wait for a rollover
if (s != s2)
{
m_offset = (int)(DateTimeMs.TickCount % 1000);
break;
}
}
}
public static void Reset()
{
systemStartMS = (DateTime.Now - new TimeSpan((long)(DateTimeMs.TickCount) * 10000)).Ticks / 10000;
}
public static void ResetTo(DateTime to)
{
systemStartMS = (to.Ticks / 10000 - (long)DateTimeMs.TickCount);
}
public static DateTime NowMs
{
get
{
// find where we are based on the os tick
int tick = (int)(DateTimeMs.TickCount % 1000);
// calculate our ms shift from our base m_offset
int ms = (tick >= m_offset) ? (tick - m_offset) : (1000 - (m_offset - tick));
// build a new DateTime with our calculated ms
// we use a new DateTime because some devices fill ms with a non-zero garbage value
DateTime now = DateTime.Now;
return new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, ms);
}
}
public static DateTime ToDateTime(long ts)
{
return new DateTime(ts * 10000);
}
/**
* Number of milliseconds from 01.01.0001
*/
public static long Now
{
get
{
return systemStartMS + DateTimeMs.TickCount;
//return NowMs.Ticks / 10000;
}
}
}
}
> Millisecond always return 0 in wince
> -------------------------------------
>
> Key: LOG4NET-412
> URL: https://issues.apache.org/jira/browse/LOG4NET-412
> Project: Log4net
> Issue Type: Bug
> Components: Appenders
> Affects Versions: 1.3.0
> Environment: NETCF
> Reporter: Son Tran
> Priority: Trivial
> Labels: DateTime,
>
> As I check the DateTime.Ticks is used in function AbsoluteTimeDateFormatter.FormatDate always return 0
> work around by using Enviroment.TichCount.
--
This message was sent by Atlassian JIRA
(v6.2#6252)