我已经看到了几个声称为日志文件创建json的log4net扩展,但格式永远不会是有效的json,这意味着该集合不在数组中而不是以逗号分隔.我使用它错了还是没有办法使用json的log4net?
<appender name="SessionFileAppender" type="log4net.Appender.FileAppender">
<file value="Session.log" />
<appendToFile value="false" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type='log4net.Layout.SerializedLayout, log4net.Ext.Json'>
<decorator type='log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json' />
<default />
<remove value='message' />
<member value='message:messageobject' />
</layout>
</appender>
Run Code Online (Sandbox Code Playgroud)
输出是:
{"date":"2017-01-29T13:45:50.7345813-05:00","level":"DEBUG","appname":"MyApp.vshost.exe","logger":"MainWindow","thread":"9","ndc":"(null)","message":"Loading new UI instance"}
{"date":"2017-01-29T13:45:50.7380842-05:00","level":"DEBUG","appname":"MyApp.vshost.exe","logger":"MainWindow","thread":"9","ndc":"(null)","message":"Loading internal localization file"}
{"date":"2017-01-29T13:45:50.7510970-05:00","level":"DEBUG","appname":"MyApp.vshost.exe","logger":"MainWindow","thread":"9","ndc":"(null)","message":"Initializing UI"}
Run Code Online (Sandbox Code Playgroud)
这是接近但不是真正有效的json.
WMI的新手,在黑暗中有点感觉,
以下代码检测连接和断开USB设备,但我还需要检测BT设备何时连接/断开(不仅仅是配对).
ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2 OR EventType = 3");
watcher.EventArrived += new EventArrivedEventHandler(HardwareDeviceChange);
watcher.Query = query;
watcher.Start();
Run Code Online (Sandbox Code Playgroud)
如果通过WMI无法实现,是否还有另外一种方法可以实现(希望尽可能避免使用32英尺的解决方案).
一直在寻找Windows.Gaming.Input命名空间,但我很难过.我应该引用什么来访问它?MSDN在这件事上实际上没有任何帮助.https://msdn.microsoft.com/en-us/library/windows/apps/windows.gaming.input.aspx
值得注意的是,我已经包括WindowsBase并System.Windows认为他们可能在那里.没运气.
还尝试过:
也不会解析命名空间.
在我的UserControl中:
public ODIF.DeviceChannel Channel
{
get { return (ODIF.DeviceChannel)GetValue(ChannelDP); }
set { SetValue(ChannelDP, value); }
}
public static readonly DependencyProperty ChannelDP = DependencyProperty.Register("ChannelProperty", typeof(ODIF.DeviceChannel), typeof(ChannelBox), new PropertyMetadata(new ODIF.DeviceChannel()));
Run Code Online (Sandbox Code Playgroud)
然后,当尝试在XAML中使用我的控件并绑定到Channel使用datatriggers时:
<local:ChannelBox VerticalAlignment="Top" HorizontalAlignment="Left" Width="200">
<local:ChannelBox.Resources>
<local:TypeOfConverter x:Key="TypeOfConverter"/>
</local:ChannelBox.Resources>
<local:ChannelBox.Style>
<Style TargetType="{x:Type local:ChannelBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding mappingConnector, Converter={StaticResource TypeOfConverter}}" Value="{x:Type ODIF:MappingConnector}">
<Setter Property="Channel" Value="{Binding mappingConnector.plugin}" />
</DataTrigger>
<DataTrigger Binding="{Binding mappingConnector, Converter={StaticResource TypeOfConverter}}" Value="{x:Type ODIF:InitialMappingConnector}">
<Setter Property="Channel" Value="{Binding mappingConnector.SourceChannel}" />
</DataTrigger>
</Style.Triggers>
</Style>
</local:ChannelBox.Style>
</local:ChannelBox>
Run Code Online (Sandbox Code Playgroud)
在XAML中引发以下错误:
属性“ Channel”不是DependencyProperty。要在标记中使用,非附加属性必须使用可访问的实例属性“ Channel”在目标类型上公开。对于附加属性,声明类型必须提供静态的“ GetChannel”和“ SetChannel”方法。 …
我已经看过其他类似的问题,但是他们似乎总是在XAML中这样做,因为这是在事件处理程序中,所以我需要找出c#中的答案。基本上,我只需要发送菜单项闪烁红色即可。
ColorAnimation ca = new ColorAnimation()
{
From = Color.FromRgb(0, 0, 0),
To = Color.FromRgb(255,0,0),
AutoReverse = true,
RepeatBehavior = new RepeatBehavior(3),
Duration=new Duration(TimeSpan.FromSeconds(.5))
};
(sender as MenuItem).Foreground.BeginAnimation(SolidColorBrush.ColorProperty, ca);
Run Code Online (Sandbox Code Playgroud) 关于HierarchicalDataTemplate似乎有大量的信息,但我很难找到足够的信息来帮助我解决包含不同类型的层次结构.
假设以下类结构:
public class classA
{
public string name{get;set;}
}
public class classB
{
public string name{get;set;}
public List<classA> subItems{get;set;}
}
public class classC
{
public string name{get;set;}
public List<classB> subItems{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
现在假设类不是自引用的原因因此在我的层次结构中保持一种类型是包含它们的属性存在根本差异,有没有办法创建类型敏感的HierarchicalDataTemplate?
我有一个HID设备,我在200hz-600hz左右与之通信,并将数据解释为代表HID设备属性的类对象.该类在其属性上实现了INotifyPropertyChanged,并且由于通信速度,我认为处理队列陷入困境,因为控件似乎变得滞后并且在几分钟后变得"框架".
是否有.net中的方法可能有助于此类事件,可能是事件处理程序池或某种类型的队列?
不幸的是,如果没有我的HID设备,我不确定我的代码是否对任何人都有用,但是生病包括一些相关的代码段只是为了显示我的实现:
public enum DataEvents { onNone = 0, onStatus = 1, onInput = 2, onOutput = 4, onReport = 8};
public class Controller: INotifyPropertyChanged, IDisposable, INotifyDisposed
{
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler Disposing;
public event EventHandler Disposed;
public event EventHandler ReportReceived;
internal void callPropertyChanged(string PropertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(PropertyName));
}
internal void callReportReceived()
{
ReportReceived?.Invoke(this, EventArgs.Empty);
}
public bool Touch1
{
get { return _Touch1; }
private set { if (value != _Touch1) { _Touch1 = …Run Code Online (Sandbox Code Playgroud) 除了迭代集合,有没有办法返回具有最高绝对值的集合中的双精度值,而不会使集合中的值实际上是绝对值?
double[] vals = new double[] { 2.3, 1.7, -3.8};
vals.Max(v => Math.Abs(v)); // This returns 3.8 instead of -3.8
Run Code Online (Sandbox Code Playgroud)