admin管理员组文章数量:1354705
I am new to WinUI development, I created a new simple WinUI 3.0 app (using Viusal Studio template Blank App, Packaged (WinUI 3 in desktop)
I also installed the following
$ dotnet add package Serilog
$ dotnet add package Serilog.Sinks.Console
$ dotnet add package Serilog.Sinks.File
This is how my App.xaml.cs constructor looks like.
public App()
{
this.InitializeComponent();
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("logs\\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Application Starting");
}
I don't see any logs on the console or file being created too. What could I be doing wrong? Are there some special permissions I need to request etc. Appreciate any tips or debugging suggestions for me, thank you.
I am new to WinUI development, I created a new simple WinUI 3.0 app (using Viusal Studio template Blank App, Packaged (WinUI 3 in desktop)
I also installed the following
$ dotnet add package Serilog
$ dotnet add package Serilog.Sinks.Console
$ dotnet add package Serilog.Sinks.File
This is how my App.xaml.cs constructor looks like.
public App()
{
this.InitializeComponent();
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("logs\\myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Application Starting");
}
I don't see any logs on the console or file being created too. What could I be doing wrong? Are there some special permissions I need to request etc. Appreciate any tips or debugging suggestions for me, thank you.
Share Improve this question edited Mar 29 at 23:12 Andrew KeepCoding 14.1k2 gold badges21 silver badges37 bronze badges asked Mar 28 at 19:49 SoftHumanSoftHuman 133 bronze badges 4- I dont think you can write files to an arbitrary location with winui3. stackoverflow/questions/61250141/… – mxmissile Commented Mar 28 at 20:25
- thank you @mxmissile it's now creating the file and writing logs into it, had give it a file path with right permissions to write as described in the thread you shared. But I don't see any console logs – SoftHuman Commented Mar 28 at 22:21
- To directly answer your title - Serilog is a .NET library - of course you can use it anywhere you can use .NET. There may be specific nuances of certain sinks on certain platforms - things like permissions and app restrictions will apply to Serilog just like it would to any other code running in an app on the same platform. – mason Commented Mar 29 at 1:11
- @mason thank you, your comment makes perfect sense, got the idea now. Since it was not working and most of examples on www are for ASP.NET I thought, may be it does not work for WinUI Apps. – SoftHuman Commented Mar 29 at 22:02
1 Answer
Reset to default 0Changing the OutputType
from WinExe
to Exe
should do the trick:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--<OutputType>WinExe</OutputType>-->
<OutputType>Exe</OutputType>
...
If you just want to see the logs for debug, you should also consider using the Serilog.Sinks.Debug sink. This sink writes logs to the Visual Studio Output window.
本文标签: Does Serilog support WinUI 30 AppsStack Overflow
版权声明:本文标题:Does Serilog support WinUI 3.0 Apps? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744016356a2576403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论