您好,我在使用 Xamarin.Forms(.NET Core 共享项目)和 Serilog 将日志写入 Android 设备上的文件时遇到问题。
到目前为止,我已经在共享项目中安装了 Serilog。将 Serilog、Serilog.Sinks.File 和 Serilog.Sinks.Xamarin 安装到我的 Android 项目中,并在 MainActivity 中初始化记录器:
Log.Logger = new LoggerConfiguration()
.WriteTo.File(Path.Combine(Environment.ExternalStorageDirectory.AbsolutePath,"XamarinLib-{Date}.txt"),
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] [{SourceContext}] {Message}{NewLine}{Exception}",
fileSizeLimitBytes: 100000000,
rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true,
shared: false,
retainedFileCountLimit: 31,
encoding: Encoding.UTF8)
.WriteTo.AndroidLog()
.CreateLogger();
Run Code Online (Sandbox Code Playgroud)
之后我从共享项目中调用记录器,如下所示:
Log.Information("Test writing to log file");
Run Code Online (Sandbox Code Playgroud)
我可以看到在 Visual Studio 调试输出中执行日志命令,但该文件根本没有创建。我已经在模拟器和实际设备上尝试了多个位置(无根访问权限)。
我也尝试以类似的方式使用 RollingFile 接收器,但没有成功。
有任何想法吗?
我和我的团队正在尝试将一些 .svg 图标放入我们的 UWP win10 应用程序中(目标和最低版本是 Windows 10 Fall Creators 更新)。
在我的资源文件中,我将 SvgImageSource 定义如下:
<SvgImageSource x:Key="PencilIcon" UriSource="Images/DeviceMenu/Icon_EditMode_grey.svg" />
Run Code Online (Sandbox Code Playgroud)
然后我继续在我的组件中使用这个图像源:
<Image Source="{StaticResource PencilIcon}" />
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的 svgs,它们都以正确的形状渲染,但都是黑色的(第一个是铅笔):
原始的 svg 看起来像这样:
这是SVG的源代码
我尝试调整拉伸、宽度、高度等,但我似乎无法让它发挥作用。
你好,我的团队和我最近开始开发一个 win10 uwp 应用程序。应用程序将有很多视图和组件,因此预计会大量使用样式,因此我们需要通过文件/文件夹结构来组织我们的样式,我们使用以下结构(不幸的是,我无法嵌入图像,请参阅链接):
无论如何,我的 Resource.xaml 将所有其他字典合并如下:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Colors.xaml" />
<ResourceDictionary Source="/Resources/Icons.xaml" />
<ResourceDictionary Source="/Resources/Fonts.xaml" />
<ResourceDictionary Source="/Resources/Converters.xaml" />
<ResourceDictionary Source="/Resources/Buttons.xaml" />
<ResourceDictionary Source="/Resources/RadioButton.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
在我的 App.xaml 中,我引用了这本词典:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Resources.xaml" />
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
现在我设法在 RadioButton.xaml 中找到了问题的根源,我使用 StaticResource 查找引用了 Colors.xaml 中定义的画笔:
<Setter Property="Foreground" Value="{StaticResource TopMenuTextBrush}" />
Run Code Online (Sandbox Code Playgroud)
如果我删除这一行,一切都会开始,但我得到以下异常:
- 异常 {Windows.UI.Xaml.Markup.XamlParseException:找不到与此错误代码关联的文本。
无法分配给属性“Windows.UI.Xaml.ResourceDictionary.Source”,因为无法将“Windows.Foundation.String”类型分配给“Windows.Foundation.Uri”类型。[行:28 位置:37]} System.Exception {Windows.UI.Xaml.Markup.XamlParseException}
有趣的是,当我用这一行注释启动应用程序并取消注释它时,visual studio 将识别画笔并正确应用它,它只会在应用程序启动时中断。我们之前在开发 WPF 时使用了相同的方法,所以我认为这可能与应用程序部署有关。
非常感谢所有帮助。