惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
D
Docker
J
Java Code Geeks
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
腾讯CDC
罗磊的独立博客
U
Unit 42
爱范儿
爱范儿
Vercel News
Vercel News
MyScale Blog
MyScale Blog

博客园 - FredGrit

WPF customize via three combied custom controls WPF DataGrid DataGridTemplateColumn DataTemplate ContentPresenter ContentTemplate WPF Customcontrol NumUpDownScroller WPF CustomControl override Template in Generic.xaml and invoke different style WPF HierarchicalDataTemplate customize via ToggleButton WPF DataGrid DataGridTemplateColumn DataTemplate call predefined DataTemplate via ContentPresenter and ContentTemplate WPF ListBox load data via contentcontrol an ItemTemplate WPF DataGrid load data from Asp.Net Core WebAPI WPF TreeView HierarchicalDataTemplate with grouped Data WPF display grouped data with GroupBox and ItemsControl WPF two listbox scroll syncchronously via behavior WPF invoke data from WebAPI,DataGridTemplate call pre defined DataTemplate via ContentPresenter WPF ListBox load data from WCF WPF datagrid load data from WCF via json, export selected items to json file WPF ItemsControl load data from WCF,DataTemplate, ContentControl WPF customize rotated wheel relentlessly via custom control WPF embed DataTemplate in HierchicalDataTemplate of TreeView WPF ContentControl, ItemsControl, ItemsPanelTemplate,VirtualizingStackPanel,convert xml string to List<T> WPF parse web.config recursively, TreeView and HierarchicalDataTemplate WPF Custom control in cs and Generic.xaml WPF ContextMenu independent visual tree resolved via Freezable implemented class WPF custom control GetTemplateChild vs FindName,NameScope separation between Logical Tree and Visual Tree, WPF ListBox ListView Datatemplate, parse xml to List via XmlSerializer and StringReader WPF TreeView HierarchicalDataTemplate, parse xml via traverse in XmlElement WPF parse xml via [XmRoot] and [XmlElement] attributes together, contentcontrol's template is ControlTemplate from Resources WPF ContentControl invoke Template from resource, reuse datatemplate WPF deserialize xml string as List via [XmlRoot] and [XmlElement] attribute WPF ContentControl Template WPF DatagridTemplate Binding DataTemplate WPF TreeView explicitly given key name to HierarchicalDataTemplate
C# Serilog both in file and console
FredGrit · 2026-03-30 · via 博客园 - FredGrit
Install-Package serilog.aspnetcore
using Serilog;

namespace ConsoleApp12
{
    internal class Program
    {
        static int idx = 0;
        static void Main(string[] args)
        {
            InitSerialLog();
            Console.WriteLine($"{DateTime.Now},Finished");
            Log.CloseAndFlush();
        }

        private static void InitSerialLog()
        {
            Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Debug()
            .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
            .WriteTo.File(
            path: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
            "CollectTest",
            "log_.log"),
            rollingInterval: RollingInterval.Day,
            rollOnFileSizeLimit: true,
            fileSizeLimitBytes: 1024 * 1024 * 1024,
            retainedFileCountLimit: 3000,
            shared: true,
            outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
            ).CreateLogger();

            while (true)
            {
                Log.Information($"{DateTime.Now.ToString("yyyyMMddHHmmssffff")}_Idx:{Interlocked.Increment(ref idx)}_{Guid.NewGuid():N}");
                Thread.Sleep(100);
            }

        }
    }
}

image

image

image

Install-Package Serilog
Install-Package Serilog.Sinks.Console
Install-Package Serilog.Sinks.File
using Serilog;
namespace ConsoleApp13
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding=System.Text.Encoding.UTF8;
            SerilogDemo();
            Console.WriteLine("Hello, World!");
        }

        static void SerilogDemo()
        {
            try
            {
                Log.Logger = new LoggerConfiguration()
                    .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
                    .WriteTo.File(
                    path:Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    "CollectTest2",
                    "log_.log"),
                    rollingInterval:RollingInterval.Day,
                    rollOnFileSizeLimit:true,
                    fileSizeLimitBytes:1024*1024*1024,
                    retainedFileCountLimit:3000,
                    shared:true,
                    outputTemplate:"{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj} {NewLine} {Exception}"
                    )
                    .CreateLogger();
                
                Log.Information($"{DateTime.Now},LogLevel.Information,program started!");
                Log.Warning($"{DateTime.Now},LogLevel.Warning,This is warning!");
                Log.Error($"{DateTime.Now},LogLevel.Error,This is error!");

                Console.WriteLine($"{DateTime.Now},Press any key to exit.");
                Console.ReadKey();
            }
            catch (Exception ex)
            { 
                Log.Fatal(ex, $"{DateTime.Now},{ex.Message}");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
    }
}
2026-03-30 23:12:58.644 [INF] 2026-03-30 23:12:58,LogLevel.Information,program started!
2026-03-30 23:12:58.687 [WRN] 2026-03-30 23:12:58,LogLevel.Warning,This is warning!
2026-03-30 23:12:58.689 [ERR] 2026-03-30 23:12:58,LogLevel.Error,This is error!
2026-03-30 23:12:58,Press any key to exit.

image

image